I want to create an Input
component to be used to compose new form elements.
const Input = ({ value, children }) => {
const [currentValue, setCurrentValue] = useState();
return <div className='input'>
{children}
</div>
};
And my Text
component would be:
const Text = (props) => {
return <Input {...props}>
<input
type='text'
value={/*how to bind to currentValue of Input*/}
onChange={/*how to call Input's setCurrentValue here*/}
/>
</Input>
}
I need to store currentValue
state in parent, because I need to manage it for many different inputs.
Also I'm stuck at how to call parent's setCurrentValue
on child's onChange
method.
Any help is appreciated.
Update: CodeSandbox
Update 2: Real code from my repository