M
M
Max Zhukov2019-03-22 19:10:47
React
Max Zhukov, 2019-03-22 19:10:47

Why doesn't data change in useCallback hook?

Data came from the back, and after that, when handleGraphSelectionChange is called, the data always remains the same and why?

const [data, setData] = useState({
        nodes: [],
        links: [],
        updatedAt: {}
    });

    const handleGraphSelectionChange = useCallback(selectedNode => {
        console.log(data);
        setData({
            nodes: data.nodes.slice(1,10),
            links: [],
            updatedAt: {}
        });
    }, [data]);

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