Logo

dev-resources.site

for different kinds of informations.

The way we store state globally in react

Published at
1/22/2023
Categories
react
webdev
reactive
rxjs
Author
aungmyatmoe
Categories
4 categories in total
react
open
webdev
open
reactive
open
rxjs
open
Author
11 person written this
aungmyatmoe
open
The way we store state globally in react

Oden Reactive Store

To leverage the power of reactive programming, we need to be able to store data in a reactive way.
This lib provides a simple way to define a reactive store for your micro-frontend application.

Installation

npm i oden-reactive-store
Enter fullscreen mode Exit fullscreen mode

Usage

Define a store which will global accessible and reactive in your application which means when you change state in
another
component it will be updated in all other components which are using the same store.

import {defineStore} from "oden-reactive-store";

export const useCounterStore = defineStore(0)
Enter fullscreen mode Exit fullscreen mode

Now you can use the store in your components like this.
You can use the store via custom hook useCounterStore which will return the current state and a function to update the
state like useState.

import {useCounterStore} from "../store/useCounterStore";

const Counter = () => {
    const [count, setCount] = useCounterStore();

    return (
        <div className="card">
            <button onClick={() => setCount((count) => count + 1)}>
                count is {count}
            </button>
        </div>
    );
};

export default Counter;
Enter fullscreen mode Exit fullscreen mode

And you can use your component like this.
When you click the counter button it will be updated in all other components which are using the same store.

function App() {

    return (
        <div className="App">
            <h1>Reactive Store</h1>
            <Counter/>
            <Counter/>
            <div>
                Counter value will change across all components due to reactive store behavior
            </div>
        </div>
    )
}
Enter fullscreen mode Exit fullscreen mode
reactive Article's
30 articles in total
Favicon
Learning AWS with Localstack and Reactive Kotlin β€” A stamps and coins implementation
Favicon
Concussion Management in Blackfalds: Expert Care at Reactive Clinic
Favicon
Making reactive applications with a Kitten Care Example
Favicon
Reactive Programming applied to Legacy Services β€” A WebFlux example
Favicon
Getting Started with Spring WebFlux
Favicon
Reactive vs. Event-Driven Programming: Weighing the Pros and Cons
Favicon
Building the Neo4j Matrix: Spring Boot, Reactive APIs, and Graph Databases
Favicon
The Article I Took So Long to Write: Concepts about Reactive Programming and RxJS
Favicon
Cloning Reactive Objects in JavaScript
Favicon
Alfama: Fine grained reactive UI library with explicit subscriptions
Favicon
Building Reactive Microservices: A Step-by-Step Guide
Favicon
Unleashing Reactive Programming: Boosting Responsiveness, Resilience, and Scalability
Favicon
Understanding Reactive Contexts in Angular 18
Favicon
WordPress Interactivity API: Detailed Explanation
Favicon
Vue reactivity for impatient devs
Favicon
Reactive vs Servlet Stack
Favicon
May I humbly submit you my front-end framework ?
Favicon
Microservice
Favicon
Component store – perfect for managing local state
Favicon
How Combine works: Operators
Favicon
How Combine works: Subscriptions
Favicon
How Combine works: Publishers
Favicon
Ability to unlearn in Software: Reactive Programming
Favicon
Yes! There’s a Technology that’s Faster than React!
Favicon
Angular Dynamic Form Using XSD
Favicon
Angular Forms: Building Complex Reactive Forms with ngJoyValidators
Favicon
Reactive Programming: a gentle introduction
Favicon
The way we store state globally in react
Favicon
Reactive Backend Applications with Spring Boot, Kotlin and Coroutines (Part 1)
Favicon
Reactive Backend Applications with Spring Boot, Kotlin and Coroutines (Part 2)

Featured ones: