Skip to content

A redux CRUD application - built on redux, react-redux and react-thunk for state management.

Notifications You must be signed in to change notification settings

sikaili99/react-redux-basics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Getting Started with Create React App

This project was bootstrapped with Create React App.

Available Scripts

In the project directory, you can run:

yarn start

Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.

The page will reload if you make edits.
You will also see any lint errors in the console.

Test if redux is working

In the console, run this

store.getState();
// output: {articles: Array(0)}

State update

To listen for state updates with subscribe with:

store.subscribe(() => console.log('Look I'm fired everytime, Redux!!'));

To dispatch an action

To change the state in Redux we need to dispatch an action by calling the dispatch method, in this case we are dispatching an action that will add an article.

store.dispatch(addArticle({ title: 'React Redux Tutorial for Beginners part 1', id: 1 }));

store.dispatch(addArticle({ title: 'React Redux Tutorial for Beginners part 2', id: 2 }));

store.dispatch(addArticle({ title: 'React Redux Tutorial for Beginners part 3', id: 3 }));

Chech the state again

store.getState();
// output: {articles: Array(3)}

To delete an article

store.dispatch(deleteArticle({id: 3 }));

Check the state again to see if the article was deleted

store.getState();
// output: {articles: Array(2)}

We can see the array has two articles now, so the article was deleted successfully!

About

A redux CRUD application - built on redux, react-redux and react-thunk for state management.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published