Answer the question
In order to leave comments, you need to log in
What's the best way to get props into React components?
Hello everyone, it became interesting, such a philosophical question, what do you think is the best way to get props in components? Immediately destructure them and use them as ordinary variables:
const App = ({ menu, user, posts }) => {
return (
<BrowserRouter>
<div>
<Header />
<div className="App">
<Sidebar items={menu} />
<Route path='/profile' render={ () => <Main user={user} posts={posts} /> } />
<Route path='/messages' render={ () => <Dialogs /> } />
</div>
</div>
</BrowserRouter>
);
}
const App = (props) => {
return (
<BrowserRouter>
<div>
<Header />
<div className="App">
<Sidebar items={props.menu} />
<Route path='/profile' render={ () => <Main user={props.user} posts={props.posts} /> } />
<Route path='/messages' render={ () => <Dialogs /> } />
</div>
</div>
</BrowserRouter>
);
}
Answer the question
In order to leave comments, you need to log in
Not to transmit, but to receive. It is transmitted from the outside and received from the inside. Do it the way you like it, the way you like it.
Yes, it doesn't matter.
This is not a philosophical question, but a matter of accepted style.
I write this way and that, if for some reason props are needed as an object, then I don’t destructure, if only values are needed - with destructuring.
I immediately use destructuring and find it a very handy thing
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question