reactjs - Putting props to state in react -


i'm working react-redux in current project , on search react wisdom came across 'convention' don't understand. other programmers tend put prop state right in constructor. why that? i've never seen in official documentation , there learned these 2 two different things hold , share data. there use in or mybe personal preference?

thanks.

it sounds pattern when need initial value outside component, want either ignore, or not immediately affect, outside (by example dispatching redux actions on each value change).

for example, maybe have form should prefilled values component gets outside (redux state) through mapstatetoprops or similar. could let every form fields onchange dispatch action changes redux state, causes incoming props change, , re-render form new value. or maybe find overkill. maybe you're satisfied keeping changing form data in component internal state until user submits form, , only then dispatch action post form data, change redux state , pass new props (like success status) down form component.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -