How to get value from this.state in another component in React?

I have a form in there is a component, in this component under certain conditions there is a setState in the resulting array. Now gash on the Submit button and I want to get this array to send to the server.
How can I get this state?

PS of course I can put the information you receive in value for my component and then pick up the value is easy, but what if there is a lot of information or even object, then this is not the correct option
June 5th 19 at 21:33
1 answer
June 5th 19 at 21:35
If the submit is in the same component - just pick the values from the state.

If in the other (to a higher level, it turns out, or several), it means that you need a component, when you change to call the callback function (which will be referred to as props), within which we will call the change of the parent state and then on submit you will easily be able to pick up the ready state

Code example:

Component A

state = {
 fromSuperComponent: '123',

callMeHandle = (e) => {
 fromSuperComponent: e.currentTarget.value

render() {
 return (
 <input type="text" value="test">
 <supercomponent callmewhendatachanged="{this.callMeHandle}" value="{this.state.fromSuperComponent}">



render() {
 <input type="text" value="{this.props.value}" onchange="{this.props.callMeWhenDataChanged}">
the data flow goes from top to bottom, events from bottom to top. Or you can use Redux. Or Context.Provider - Clyde commented on June 5th 19 at 21:38

Find more questions by tags JavaScriptReact