4 ms·
I don't know if React could allow set children's data via parent, like $childRef.setData({ data }) When i see this code in a Vue codebase, my mind got hurt.
by revskill 6y ago
I don't know if React could allow set children's data via parent, like
$childRef.setData({ data })
When i see this code in a Vue codebase, my mind got hurt.
I still prefer React due to its consistent reasoning about data flow in the app.
- onion2k 6y agoThat sounds like the equivalent to React's forward refs. https://reactjs.org/docs/forwarding-refs.html https://reactjs.org/docs/forwarding-refs.html
- acemarke 6y agoNo, that's very different, in two ways. First, `$childRef.setData()` appears to be the conceptual equivalent in React of `childClassComponentInstance.setState({someField})`. While that's technically possible, it's _extremely_ non-idiomatic in React and completely discouraged. Second, "forwarding refs" is a feature specifically designed to allow a component to apply a ref to something _inside_ of itself. For example, the React-Redux `connect` API uses ref forwarding to allow `<ConnectedComponent ref={instanceRef}>` to hand back the inner wrapped component, not the outer wrapper component from the library. It doesn't have anything to do with calling a state setting function on a component in and of itself.