nonopolarity
nonopolarity

Reputation: 150966

In React / Redux, can we pass data from any component to another component, by the way of Redux?

Since Redux is just the one and only (and the main) data store for the whole app, can we pass data from

  1. child component to parent component
  2. child to sibling components
  3. or any component to any other component

just by emitting an action with data to generate a new app state to be able to pass the data?

Upvotes: 0

Views: 156

Answers (1)

Muhammad Zeeshan
Muhammad Zeeshan

Reputation: 4748

Let's start from the beginning.

Why we use Redux?

Redux is an open-source JavaScript library for managing application state. It is most commonly used with libraries such as React or Angular for building user interfaces. Redux comes in the scenario when we want to share state between components by having a single source of truth. It creates only one centralized store that holds the data.

Passing data from child component to parent component

If you want to pass the data from child component to parent component, you can do that without redux via props.

Passing data from child to sibling components

If you want to pass the data from child to sibling components, there are two ways. Either use redux store or lift the state up and pass it as props from child parent.

or any component to any other component

It depends where the component is, do they have any connection like (Parent-Child), if yes then props otherwise redux store.

Upvotes: 1

Related Questions