I have a React component which receives an array or objects via props
. Something I would like to do is have an event re-order these props. However, it seems that React re-rendering only occurs when state
changes.
Right now I have the ordering handled in the parent object and pass the method to handle the ordering through as a prop, but ideally I want the component responsible for rendering these objects to also handle the ordering.
Chucking props
into state
seems bad, but what's the best thing to do here?
One can not change props directly. One can only update state by using setState() .
Props are overwritten when re-rendering When Vue re-renders your component — which happens every time something changes — it will overwrite any changes you have made to your props. This means that even if you try to mutate the prop locally, Vue will keep overwriting those changes.
To run a mutation, you first call useMutation within a React component and pass it a GraphQL string that represents the mutation. When your component renders, useMutation returns a tuple that includes: A mutate function that you can call at any time to execute the mutation.
A mutable object is an object whose state can be modified after it is created. Immutables are the objects whose state cannot be changed once the object is created.
Props are immutable, but in your case it seems that your data does not change, only the sort order changes, so you can:
getInitialState
to return the default sort orderIf 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