Skip to content

4.0.0

Compare
Choose a tag to compare
@RichardLindhout RichardLindhout released this 01 Jun 21:46

We made our library even smaller from 700 bytes to 500 bytes πŸ‹οΈβ€β™€οΈ ⚑️ πŸ‹οΈβ€β™‚οΈ..
Our api changes will also make your application smaller since you need less imports.

Breaking changes

You can remove setRidgeState, getRidgeState, useRidgeState imports in v4.

setRidgeState migration

import {setRidgeState} from 'react-ridge-state'
import {cartProductState} from '../cartProductState'
setRidgeState(cartProductState, [{product:1}])

Will be changed in

import {cartProductState} from '../cartProductState'
cartProductState.set([{product:1}])

getRidgeState migration

import {getRidgeState} from 'react-ridge-state'
import {cartProductState} from '../cartProductState'
const products = getRidgeState(cartProductState)

Will be changed in

import {cartProductState} from '../cartProductState'
const products = cartProductState.get()

useRidgeState migration

import {useRidgeState} from 'react-ridge-state'
import {cartProductState} from '../cartProductState'

function Component(){
    const [products,setProduct] = useRidgeState(cartProductState)
}

Will be changed in

import {cartProductState} from '../cartProductState'

function Component(){
    const [products,setProduct] = cartProductState.use()
}

Features

  • You can use callbacks in the global set
  • You can use callbacks after state has set
cartProductsState.set(
  (prevState) => [...prevState, { id: 1, name: "NiceProduct" }],
  (newState) => {
    console.log("New state is rendered everywhere");
  }
);
  • You can do things after state has been set from somewhere
const authState = newRidgeState<AuthState>(
  getInitialState() || emptyAuthState,
  {
    onSet: (newState) => {
      // save to local storage
      localStorage.setItem(authStorageKey, JSON.stringify(newState))
    },
  }
)