Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

My own redux implementation with typescript. I implemented createStore, useSelector, useDispatch and other things. Check the website below to see how it works in real time.

NotificationsYou must be signed in to change notification settings

IlyaAgarishev/my-own-redux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logo

My Own Redux

About

My own redux implementation with typescript. Integrated this technology into react app to show how it works in real project.

Things that has been implemented:

  • createStore(subscribe, unsubscribe, getState, dispatch)
  • useSelector
  • useDispatch
  • reducer
  • persist
  • logger
  • Anti-rerender logic (redux prevState and current state comparison)

screenshot

How it works

Store is created bycreateStore function. Store is a state keeper.useSelector is used to subscribe on store to see state changes. If required state field is changed, react component whereuseSelector is called will be re-rendered. You can find all this custom redux logic inmyOwnRedux folder.

This is howuseSelector logic looks like:

constuseSelector=(selector:SelectorCallback)=>{const[state,setState]=useState<State>({});useEffect(()=>{constselectedState=selector(store.getState());setState(selectedState);constunsubscribe=store.subscribe((previousState,currentState)=>{constprevState=selector(previousState);constnewState=selector(currentState);// Anti-Rerender logicconststateHasBeenChanged=!isEqual(prevState,newState);if(stateHasBeenChanged){setState(newState);}});return()=>{unsubscribe();};},[]);returnstate;};

How to start locally

  1. npm install - install all dependencies
  2. npm start - start a project

Technologies used

  • React
  • Typescript

About

My own redux implementation with typescript. I implemented createStore, useSelector, useDispatch and other things. Check the website below to see how it works in real time.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp