DEV Community

Naveen Dinushka
Naveen Dinushka

Posted on

1 1

How to create a basic redux store? (Freecodecamp notes)

Lets answer some basic questions

1) What is Redux?
Redux is a state management framework that can be used with number of different technologies, including React. Note that Redux can be used with different technologies and not only React, it is just popular for being used with React.

2) What is a Redux store?
Redux store is the single source of truth when it comes to application state , if we had 3 components in an app and with 3 different states , the entire state of your app would be defined by a single state object housed in the Redux store. This also means that any time a piece of your app wants to update , it must do so through the redux store . This makes it easier to track the state of your app.

3) What are some important functions and keywords we will need to know before we create a redux store?

  • Redux store is an object which holds and manages application state
  • createStore() on Redux object is used to create a store
  • createStore takes in reducer function as a required argument
  • We can use .

4) Declare a variable and assign it to the createStore() method passing in the reducer as an argument

const reducer = (state = 5) => {
return state;
}
// Redux methods are available from a Redux object
// For example: Redux.createStore()
// Define the store here:
const store = Redux.createStore(reducer)
view raw redux_1.js hosted with ❤ by GitHub

5) How can we retrieve the state from a redux store?

//Once a store has been created we can retrieve current state with .getState() function
const store = Redux.createStore(
(state = 5) => state
);
const currentState= store.getState()
view raw redux_2.js hosted with ❤ by GitHub

Knowledge check

1) What is Redux?
2) What is a Redux store?
3) What are some important functions and keywords we will need to know before we create a redux store?
4) How to declare a variable and assign it to the createStore() method passing in the reducer as an argument
5) How can we retrieve the state from a redux store?

NOTE: These are notes from FreeCodeCamp https://www.freecodecamp.org/learn/front-end-development-libraries/redux

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️