Could you tell me please, how can I duplicate the values of the states value from the child component Child to parent Parent. The child component implements the increment and decrement of the state on the buttons. The value should also be displayed in Parent. Thanks!
import React, {useState} from 'react';
import Child from "./Child";
const Parent = () => {
const [value, setValue] = useState(0);
return (
<>
<span>{value}</span>
<Child data={value} />
</>
);
}
export default Parent;
import React, {useState} from 'react';
const Child = ({data}) => {
const [value, setValue] = useState(data);
const increment = () => {
setValue(prevState => prevState + 1)
};
const decrement = () => {
setValue(prevState => prevState - 1)
};
return (
<>
<button onClick={increment}>+</button>
<span>{value}</span>
<button onClick={decrement}>-</button>
</>
);
};
export default Child;