4 ms·
I appreciate the effort, but it's a bit over my head with respect to react stuff. For instance, I'm not sure what's meant by needing to merge props. I was und
by recursive 4y ago
I appreciate the effort, but it's a bit over my head with respect to react stuff.
For instance, I'm not sure what's meant by needing to merge props. I was under the impression that you could pass a subset of properties as an argument to setState, and all else would remain untouched.
I wasn't thinking of using HOC's. I've done a bit of react, but never touched them. I'm just thinking of reusing logic using the same techniques I use to reuse logic in code. React famously asserts "it's just javascript". Javascript provides a way of reusing logic, namely functions. If I have two class components that have the same logic in them, I'm imagining just putting that code in a function. This is not a sophisticated argument. There might be some reason that wouldn't work, but I don't know what it is.
- orange8 4y ago> React famously asserts "it's just javascript". I think that specifically deals with when using JSX, compared to other templating systems.
- codeptualize 4y agoWith merge props I mean passing down the local state to the next component. If you see the react article I linked it’s the injectedProps. I think this might be quite common, if you haven’t experienced HOC hell I can understand the confusion why hooks are necessary. In terms of putting it in a function: there is only one state object per component, you could pass setState around, but you can imagine what would happen if many functions call it. It’s also a lot more effort on the implementation as you would have to basically pass state, and call do some sort of update in the lifecycle methods. It would probably work for one function, but with many it will get problematic. You would almost have to write your own pseudo hooks framework to make this work in a decent way.
- bayesian_horse 4y agoYou shouldn't pass properties to setState. That's a very non-reactive kind of thing. Just use the properties directly. They should be immutable.
- recursive 4y agoI confused state and props. The distinction between the two has always been a bit hazy to me. I'm not sure what "non-reactive" means.
- bayesian_horse 4y agoA React component is supposed to be a pure function, a mapping from props+context as input into an output which is a React element plus sideeffects (which when executed by the React library will often change the context). State lives in the context. To illustrate statefulness: If you drop a flummy ball on the floor, it will bounce back and doesn't change. If you drop an egg, it will change and you can't drop it easily again. The ball is stateless, the egg is stateful.