So what i'm trying to do is pass a number to the child component, which will only be passed on the first render. After that i'm trying to change the current value and pass the value from the child, back to the parent component. However i'm not able to pass price to child, as i'm receving undefined.
Not sure how I can pass the data in this context, any ideas?
function Parent(props, {price}) {
const [amount, setAmount] = React.useState("200");
function handleChange (newValue) {
setValue(newValue);
}
// We pass a callback to Child
return <Child price={amount} value={value} onChange={handleChange} />;
}
function Child (props, {price}) {
const [amount, setAmount] = React.useState("");
function handleChange(event) {
setAmount(event.target.value)
// Here, we invoke the callback with the new value
props.onChange(event.target.value);
}
useEffect(() => {
setAmount(price) //Pass value from parent if it has one
}, [])
return <input value={props.value} onChange={handleChange} />
}