-2

I am currently working in React with two files. File A(upper component) is written in function type React and File B(Lower component) is written in Class type React and they have variable X in common.

The question is how to change state of variable value using input tag at file B.

function A() { const [open,setOpen] = useState(false); const[value,setValue] = useState(''); const onChange=e=>setValue(e.target.value); return ( <B /> } class B extends Component { render() { }; return ( <input value={this.state.keyword} /> 

I just started studying, so I hope there is a detailed explanation and code. Thank you

1

1 Answer 1

0

Check this out.

const A = () => { const [open,setOpen] = useState(false); const [value,setValue] = useState(''); const onChange = e => setValue(e.target.value); return ( <B onChange={onChange} value={value}/> ) } class B extends Component { render() { return ( <input value={this.props.value} onChange={this.props.onChange}/> ) } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.