Hi All,
I’m trying to pass props from a parent component to a child component. If the parent component state updates, I am passing the updated state to the child component as props, and trigger a re-render of child component. If the onclick function trigger in child component then parent state should be updated. Can someone help in doing this:
Example:
@react.component
let make = () => {
let (count, setCount) = React.useState(() => 0)
Parent Component
Count:{count}
} @react.component
let Child = (props) => {
let handleClick = () => {
props.setCount(e=>e+1)
}
There seems to be some issues with your example, for one you need to use labelled arguments (e.g. ~children) for components.
Here’s a working example, and as an aside, it’s common to try to only expose what the child needs to know rather than exposing too many details about the implementation. One benefit of this approach is that if you’re refactoring, you’ll likely end up having to touch less files.