N
N
Nikita Andreevich2020-06-08 16:24:46
React
Nikita Andreevich, 2020-06-08 16:24:46

How to call a function from parent that is in child?

I have 3 components.
1 - parent (I receive data in it and there is a filter implementation)
2 - called in the parent (gets an array and renders it)
3 - each element of the array.

when you press a button in component 1, you need to call a function that is in component 3.

The logic is this:
component 1 receives data, user filters are applied to this data, and already filtered data is transferred to component 2.

The 2nd component receives the array , renders it and passes each element of the array to the 3rd component .

The 3rd component takes the data and displays it as a single list item. The swipe logic is also implemented. When swiping left or right, a request is sent to the server with the changed data about the element, and the cancel button is called (modal window in 1 component). By clicking on which you need to cancel the changes and send the previous status of the element to the server, and this previous status is stored in the 3rd component.
Even if I take this status to the global store, then I will have to transfer data from 1 component to the second (in order to send an update to the server). It turns out everything will be the same, only not with 3 components, but with two. components.

1-3 is nesting where 1 parent

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-06-08
@NikitosAndreevich

more information is needed, but in general, move the function to where the window is being drawn, that is, in No. 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question