S
S
stepbystep2020-02-23 19:35:06
React
stepbystep, 2020-02-23 19:35:06

React: How can I pass data on onClick?

How can I pass data from one component to another component.

Custom.js

const Custom= ( {dialogs, getDialogs} ) => {

    const allUserMessageData = dialogs;

    return (
        <Container>
            <AppChatList>
                <ul>
                    {
                        allUserMessageData.map( (d, i)=> {

                            const getCurrentUserData = {
                                position: d.id
                            };

                            return (
                                <li key={i}>
                                    <Link
                                        onClick={()=> (console.log(getCurrentUserData ))}
                                          to={`/messages/chat/${d.chat_token}`}>
                                        <AppMessageUserList dialog={d} />
                                    </Link>
                                </li>
                            )
                        })
                    }

                </ul>
            </AppChatList>
        </Container>
    );
};

export default Custom;


The logic is such that when I click on the link, I have to send the id of the current user (the data is taken from redax) to another function.js file where I will process the received data

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Chingiz Mammadov, 2020-02-24
@yaverm

Maybe you just need to read https://reacttraining.com/react-router/web/example...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question