Skip to content

Investigate using Redux for pseudo-local component state #159

@gaearon

Description

@gaearon

As @slorber notes, once you go single-treeish, local component state begins to bother you.

I don't feel strongly about it (I'm fine with some local component state here and there), but it would be interested to explore API and implementation-wise the idea of replacing React local component state with state backed by Redux with “ephemeral” reducers whose data is erased when their owner component unmounts.

I'm not sure if I'm actually making sense here.. Let's say that the litmus test is:

  • Have some API that looks similar to React's local state API. For example, a container component that injects state and setState as props.
  • Unlike React's local state API, under the hood, it works by emitting actions like { type: SET_LOCAL_STATE, ownerComponentId: '42424242' }
  • There is a reducer that handles these actions. The container component subscribes to the slice of the state governed by that reducer
  • (The nice part) By default component IDs are unique but you can specify a function that generates the key from props. This lets components “mirror” the same state or “transplant” it across the tree. (cc @chenglou)

Related: rethinking React's key and state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DiscussionA status update or open-ended community conversation.Future IdeaHelp WantedExtra attention is needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions