Git Product home page Git Product logo

Comments (7)

cyphercider avatar cyphercider commented on May 30, 2024 1

Yeah, that's exactly what I had in mind for useMemo.

from react-hooks-global-state.

dai-shi avatar dai-shi commented on May 30, 2024

Option 1: we rotate the index. % 31
Option 2: we use multiple contexts for each 31 items.
Option 3: multiple contexts for each items. Do not rely on observedBits

from react-hooks-global-state.

cyphercider avatar cyphercider commented on May 30, 2024

Assuming you abstract the implementation away from the user, I guess the decision criteria are (?)

  1. Potential high overhead or general “misuse” of the react context feature if potentially hundreds of contexts are created as with option #3
  2. Rendering efficiency of the app to the extent that with #1, some components will undesirably receive a state change when an overlapping index has changed

I don’t know enough about the implementation of Context in the react codebase to know if #1 is a concern.

It’s still not clear to me how we may subscribe to deep state or if that is even desirable considering we can receive a state change for the high level state but avoid re renders using things like memo() for functional components and useMemo for computed values.

from react-hooks-global-state.

dai-shi avatar dai-shi commented on May 30, 2024

Thanks. I'm not sure either how much overhead creating hundreds of contexts leads.
Another concern is whether observedBits will ever be official...

BTW, https://github.com/dai-shi/react-context-global-state is already taking the Option 3 approach.

from react-hooks-global-state.

dai-shi avatar dai-shi commented on May 30, 2024

but avoid re renders using things like memo()

something like this?

11_deep / Person.tsx

const PersonFirstName = () => {
  const [value] = useGlobalState('person');
  const { firstName } = value;
  return useMemo(
    () => (
      <div>
        First Name:
        <TextBox text={firstName} />
        <input
          value={firstName}
          onChange={setFirstName}
        />
      </div>
    ),
    [firstName]);
};

from react-hooks-global-state.

dai-shi avatar dai-shi commented on May 30, 2024

Option 4: we pass non-updating "store" in the context, and let hooks subscribe for key-based changes. This is mostly like the previous implementation which requires useState.

from react-hooks-global-state.

dai-shi avatar dai-shi commented on May 30, 2024

Turns out that the current implementation already takes the option 1 approach.
I keep it as is, otherwise the library implementation gets much bigger.
This limitation should be clearly noted in README.md.

from react-hooks-global-state.

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.