GithubHelp home page GithubHelp logo

Comments (5)

weltenwort avatar weltenwort commented on June 10, 2024 1

I've come across this a few times while working on https://github.com/elastic/kibana. The solution I used was to decompose the App, providers and content into several components so the context value can be accessed via the hook as usual:

const App = () => (
  <AppProviders initialValue="a">
    <AppEffects />
    <AppContent />
  </AppProviders>
)

const AppProviders = ({ children, initialValue }) => {
  <ValueProvider initialValue={initialValue}>
    {children}
  </ValueProvider>
}

const AppEffects = () => {
  const [, setValue] = useValueContext();

  useEffect(() => {
    setTimeout(() => {
       setValue('b');
    }, 2000);
  }, [setValue]);
}

I find that pretty readable without the need for a more complex API. @awkpagong, could that work for you?

from constate.

awkpagong avatar awkpagong commented on June 10, 2024 1

@diegohaz ok I will try @weltenwort's suggestion then. It's a bit more verbose, but I agree it will keep the API simple. Thanks for the suggestions guys!

from constate.

diegohaz avatar diegohaz commented on June 10, 2024

I've never seen that. Maybe something like this?

function useValueWithRef({ providerRef }) {
  ...
}

...

<ValueProvider providerRef={ref} />

from constate.

awkpagong avatar awkpagong commented on June 10, 2024

I've never seen that. Maybe something like this?

function useValueWithRef({ providerRef }) {
  ...
}

...

<ValueProvider providerRef={ref} />

@diegohaz thanks for the suggestion. I will try that. And thanks for all your amazing work on this package!

from constate.

diegohaz avatar diegohaz commented on June 10, 2024

I still don't understand the use case. But, If @weltenwort's solution solves your problem, it's preferable.

from constate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.