Reactn Versions Save

React, but with built-in global state management.

v2.2.7

4 years ago
  • Exports the Setter function type for setting the global state. #155 (Thanks @rolandzwaga!)

v2.2.6

4 years ago

Bug fixes 🐛

  • Fixes issue where useGlobal() hook with no parameters would sometimes not trigger a re-render on state changes after the first. #150 (Thanks @m4ttheweric!)

Miscellaneous 📃

  • Upgrades dev dependencies to latest, allowing asynchronous act. 👍
    • Deprecated unit tests for non-latest versions of React, because they do not support asynchronous act. 😢

v2.2.5

4 years ago

2.2.5

  • Removes use of deprecated componentDidUnmount for class components. #134

2.2.3/2.2.4

  • Batches subscriptions using ReactDOM. #129
  • Reverted due to lack of React Native support.

2.2.2

  • Memoizes useGlobal's setter function. #123

2.2.1

  • Fixes TypeScript issue where map of dispatchers was not extensible.

v2.2.0

4 years ago

New Features

  • Global reducers now receive a dispatch function in addition to the dispatch object. This dispatch function asynchronously calls setGlobal and returns the new global state, allowing you to await the change. This is the first step towards sagas. #116
function myReducer(global, dispatch, ...params) {
  await dispatch({ change: 1 }); // <-- dispatch is a function
  await disaptch.someOtherReducer(params); // <-- dispatch is a map
  await dispatch({ change 2 });
}

v2.1.6

4 years ago

New Features ✨

  • ReactN now supports all versions of React >= 0.14. #60
    • Thanks @janezk7 and @davidrenne!

Bug Fixes 🐛

  • Fixed withGlobal using the default global state instead of a Provider's global state for Components inside a Provider in versions of React >=16.3 <16.6.

Miscellaneous

  • Upgraded react-testing-library to @testing-library/react.

  • Added documentation for useDispatch and useGlobal to the README.

v2.1.5

4 years ago

New Features ✨

  • Added a withInit HOC that initializes the global state and its reducers. #84
    • Thanks to the ReactN Discord channel and @ZinoKader!

Bug Fixes 🐛

  • [TypeScript] Reducers added via addReducer now match their definitions in reactn/default's Reducers interface. #105
    • Thanks @MikeMeyers2504!

v2.1.3

4 years ago

Bug Fixes 🐛

  • Fixed class components only unsubscribing from a single property on unmount. #85
    • Massive thanks to @umbertoghio for providing two repositories to reproduce this!

New Features ✨

  • The dispatch function returned by useDispatch, when providing a property reducer and property name, can now be destructured. #90
    • This behavior is analogous to React's native useReducer behavior.
    • const [ value, dispatch ] = useDispatch(propertyReducerFunction, propertyName);

Miscellaneous

  • A TypeScript PropertyDispatcher type has been added to reactn/types/dispatcher, referencing a dispatcher that can be destructured.

v2.1.2

4 years ago

Bug Fixes 🐛

  • Fixes TypeScript complaint about ReactN Components with no generics. #88 (Thanks Discord user Riccardo#9449!)

v2.1.1

4 years ago

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

v2.0.4

4 years ago

Breaking Changes 💔

The follow breaking change to withGlobal was not deemed worthy of a major version bump, because it should have been included in 2.0.0.

  • The getter and setter function parameters are no longer of type (global, props) => ... and (setGlobal, props) => ... respectively.
    • Both now accept the dispatch object as a second parameter, which contains and dispatches your global reducers.
  • The getter function is now of type (global, dispatch, props) => ....
  • The setter function is now of type (global, dispatch, props) => ....

Before:

export default withGlobal(
  (global, props) => ({ ... }),
  (setGlobal, props) => ({ ... }),
)(MyComponent);

After:

export default withGlobal(
  (global, dispatch, props) => ({ ... }),
  (setGlobal, dispatch, props) => ({ ... }),
)(MyComponent);

Bug Fixes 🐛

  • withGlobal is now fixed on React Native when there is no Provider. #78 (Thanks @Brianop, @BDQ!)
    • Unlike React for Web, React Native returns a truthy Context when the Context is missing.
    • This was erroneously resulting in ReactN believing it had the global state when it did not.

Miscellaneous 📄

  • Added unit tests for withGlobal to validate that it works with a Context, without a Context, and via a Provider. #66
  • Fixed a TypeScript error that Provider.withGlobal() required parameters, when they are optional.
  • Moved the ReactN Provider type to 'reactn/types/provider'.
  • Moved the useGlobal types to 'reactn/types/use-global'.
  • Moved the withGlobal types to 'reactn/types/with-global'.