Skip to content

Synchronization of props with state is an anti-pattern #70

@furqanZafar

Description

@furqanZafar

http://facebook.github.io/react/tips/props-in-getInitialState-as-anti-pattern.html

A component should not sync its state with its props, the 2 must be separate, like in any form input element in React, i.e an input element created using: <input value={apple} type={text}/> will always have the value 'apple' no matter what the user does.

The only way to change the value of the input component is by updating its props. <input value={this.state.x} type={text} onChange={this.handleChange} />

However this is not true in the case of react-select, as it syncs its state with props and the state can also be changed by user-input (multiple sources of truth).

The render method must use values from props instead of state. State maybe used to support access to value in the handleChange event, analogous to (this.refs.myInputElement.getDOMNode().value)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions