Reputation: 181
const App = () = {
return(
<Article
render={
(getContextProps) => (
<Context {...getContextProps()}>{sometext}</Context>
)}
/>
)
}
Hi Everyone, recently I came cross this piece of code, function component in react, in the render attribute I passed in, which has getContextProps
as a variable, i am confused about what is {...getContextProps()}
means, my understand is that need to pass getContextProps
as props to the child Context component as attribute using rest operator, but I don't know why the syntax is {...getContextProps()}
so its a variable or its a function? is that some particular syntax for React?
Upvotes: 1
Views: 50
Reputation: 282030
The above case is an example of using JSX spread attributes syntax
to pass on dynamic pops to the Context component.
A simplified version of the above code would be
const App = () = {
return(
<Article
render={
(getContextProps) => {
const props = getContextProps();
(
<Context {...props}>{sometext}</Context>
)}}
/>
)
}
Now in tha above code, getContextProps
would return an object that you would spread an pass as props to the Context
component
Upvotes: 1