Answer the question
In order to leave comments, you need to log in
Rendering a component based on ajax request results?
There is data requested from the server via useEffect( () => {fetch(...)} ) (once)
There is a function that processes this data, fitting it to the structure of the component, and executes setState() to apply the changes and render.
I understand that useEffect is not very friendly with setState, so the question is how to organize the chain [data acquisition] -> [data processing] -> [setState]?
Answer the question
In order to leave comments, you need to log in
I understand that useEffect is not very friendly with setState, so the question is how to organize the chain [data acquisition] -> [data processing] -> [setState]?
const [data, setData] = React.useState(null)
React.useEffect(() => {
const fetchedData = /* как-то данные получить */
setData(fetchedData)
}, [])
return data ? <p>{ JSON.stringify(data) } </p> : null
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question