Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

2.1.1

Compare
Choose a tag to compare
@quisido quisido released this 04 Jun 15:45
· 70 commits to master since this release

New Features ✨

  • Allows you to specify a global state property name when using useDispatch with a function. This behaves closely to how React's native useReducer works. #82
import React, { useDispatch, useGlobal } from 'reactn';

const INITIAL_COUNT= 0;

setGlobal({ count: INITIAL_COUNT});

const doMath = (count, action) {
  switch (action.type) {
    case 'ADD' :
      return count + action.value;
    case 'SUBTRACT':
      return count - action.value;
    case 'RESET':
      return INITIAL_COUNT;
    default:
      return count;
  }
};

function MyComponent() {
  const [ count] = useGlobal('count');
  const dispatchMath = useDispatch(doMath, 'count'); // <-- use doMath to modify count
  return <>
    <button onClick={() => dispatchMath({ type: 'ADD', value: 1 })}>
      Add 1
    </button>
    <button onClick={() => dispatchMath({ type: 'SUBTRACT', value: 3 })}>
      Subtract 3
    </button>
    <button onClick={() => dispatchMath({ type: 'RESET' })}>
      Reset
    </button>
    <strong>Count:</strong> {count}
  </>;
}

Miscellaneous 📃

  • Fixed useDispatch parameters in README not having been updated to include dispatch in 2.x. #87 (Thanks @yezyilomo!)
  • Added ReactN DevTools to documentation. #80