0

I want to write something like this in a functional component. How do I do it?

setState({ allowScroll: false }, () => {
  setState({ messages: list }, () => {
    setState({ allowScroll: true });
  });
});
Inaara Kalani
  • 265
  • 7
  • 24
  • 1
    There is not callback after setState. In my code I use global variable. I change it in function, variable: step1, step 2.. before return from function. – Blazej Kita Jan 16 '23 at 13:28
  • https://stackoverflow.com/questions/42038590/when-to-use-react-setstate-callback – Blazej Kita Jan 16 '23 at 13:34

1 Answers1

0

Something like this :

const [allowScroll, setAllowScroll] = useState(false);
const [messages, setMessages] = useState([]);

// useEffect ?
setAllowScroll(false);
setMessages(list);
setAllowScroll(true);
Johan
  • 2,088
  • 2
  • 9
  • 37