If a reducer function can override a prop like this:
return {...state, foo: action.payload };
Then if we have a component as such:
const MyComponent = (props) => {
return <div>{props.foo}</div>;
}
How do I override in the same manner as above?
I want to do it like below but it doesn't work
<MyComponent {...props, foo: 5} />
You need to pass it the same way you would pass props to an xml
element.
<MyComponent {...props} foo={5} />
You should also checkout the Component and Props guide by react.
You should try:
<MyComponent {...props} foo={5} />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.