O
O
OWIII2020-06-11 10:00:24
JavaScript
OWIII, 2020-06-11 10:00:24

How to call ONCE action before component render?

Hi all!
Please tell me what I can't figure out.
There is the following task:
The client follows the link from his mail to the application on the page to set a new password.
This link contains a verification code that needs to be obtained and sent to the back before the component is rendered.
Accordingly, if the answer is 200 - then we render the component, rather than - we show all sorts of errors.
I have functional components, not classes.
QUESTION: How to call action on this post request before rendering the component?
And you need to run it once) I

'm grateful if you help me figure it out.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Loli E1ON, 2020-06-11
@OWIII

const dispatch = useDispatch();

useEffect(() => {
   dispatch(myAction());
}, [dispatch]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question