Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
120
rated 0 times [  123] [ 3]  / answers: 1 / hits: 19751  / 9 Years ago, tue, march 31, 2015, 12:00:00

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?


More From » reactjs

 Answers
17

Props are immutable, but in your case it seems that your data does not change, only the sort order changes, so you can:




  • keep your data and sort functions as props

  • store your sort order in state

  • maybe use getInitialState to return the default sort order

  • when sort order is changed, state is set so re-render happens


[#67245] Saturday, March 28, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aidan

Total Points: 72
Total Questions: 95
Total Answers: 121

Location: Uzbekistan
Member since Sat, Feb 27, 2021
3 Years ago
aidan questions
Mon, Oct 11, 21, 00:00, 3 Years ago
Wed, Sep 29, 21, 00:00, 3 Years ago
Sun, Sep 5, 21, 00:00, 3 Years ago
Thu, Jan 16, 20, 00:00, 4 Years ago
;