L
L
lookingfor22021-07-27 13:06:18
React
lookingfor2, 2021-07-27 13:06:18

How to synchronously deliver data to redux?

const Parent = (props) => {
  <Child/> // тут дочерний со своим состоянием
  <button className="parent-submit" onClick={() => postData()}/>
}

const Child = () => {// как доставить state в Redux по клику на .parent-submit
  const [state, setState] = useState({})
}

const postData = () => async (dispatch, getState) => {
const {base} = getState();
const {data} = base;
  axios.post(data)
}


There is a parent component, how to click on the .parent-submit button, send the state of the Child component to redux. At the same time, in the postData method, have time to receive it and send the actual data. Due to asynchrony, I sometimes do not have time to get the actual data of their child component.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question