DEV Community

[Comment from a deleted post]
Collapse
 
atthoriq profile image
At Thoriq

cool! i'll try it soon. but can you share how it differs from redux?

Collapse
 
malloc007 profile image
Ryota Murakami

Originally I'm fan of Redux! So I could describe with long text containing trivial thing...
We call Redux in React world generally, that's combined 2 another library "React" "Redux" by "react-redux".

So, Redux(combined React) manage global value based on Flux essence. you know Dispatch Named Action with payload...

My React AppState has nothing to do with Redux.
Which constructed React build-in feature "state/context/hooks".

Thank you, this is great question I think.
I should start write more straight to understand post with sample code 👨‍💻

short answer is... React AppState designed set/get direct values 🌍

import { useAppState } from '@ryotamurakami/react-appstate'

const MyComponent = () => {
  const [appState, setAppState] = useAppState()

  function toggleDarkTheme() {
    setAppState({ isDarkTheme: !appState.isDarkTheme})
   }

   return (<button onClick={toggleDarkTheme}>{appState.isDarkTheme ? 'Disable DarkMode?' : 'Enable DarkMode!' }</button>)

}

Collapse
 
atthoriq profile image
At Thoriq

it seems very simple. i am currently developing react project with redux as its state management and i am a newbie here. i should probably try yours soon! thank you for the explanation :)

 
malloc007 profile image
Ryota Murakami

Your welcome! 🤗