I just want to know is it possible to delete react component props safely from the component.
Is there any function like
this.destroyProps({someProp})
The React philosophy is that props should be immutable and top-down. This means that a parent can send whatever prop values it likes to a child, but the child cannot modify its own props. What you do is react to the incoming props and then, if you want to, modify your child's state based on incoming props.
A component cannot update its own props unless they are arrays or objects (having a component update its own props even if possible is an anti-pattern), but can update its state and the props of its children.
React props can be accessed as an object or destructured Or they can be destructured, since props will always be an object, into separate variables. If you have a lot of props that you're passing down to your component, it may be best to include them on the entire props object and access them by saying props.
No, you can't. The props of a react component are immutable and are not supposed to be changed by the component.
If you need to work with the data locally, you could use the state of the component, or better create a local copy of the prop data.
If you were passing the props onto a child component, you could create a new object, delete the properties from that and then pass to the child.
const childProps = { ...this.props };
delete childProps.someProp;
return (
<ChildComponent {...childProps} />
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With