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

Releases: CharlesStover/reactn

2.2.7

04 Apr 22:57
a66d684
Compare
Choose a tag to compare
  • Exports the Setter function type for setting the global state. #155 (Thanks @rolandzwaga!)

2.2.6

18 Feb 18:53
Compare
Choose a tag to compare

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. 😒

2.2.1 - 2.2.5

31 Jan 21:09
83255c4
Compare
Choose a tag to compare

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.

2.2.0

18 Aug 18:07
Compare
Choose a tag to compare

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 });
}

2.1.6

21 Jul 22:11
Compare
Choose a tag to compare

New Features ✨

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.

2.1.5

20 Jul 20:50
Compare
Choose a tag to compare

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

2.1.3

10 Jun 03:50
Compare
Choose a tag to compare

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.

2.1.2

04 Jun 17:25
Compare
Choose a tag to compare

Bug Fixes πŸ›

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

2.1.1

04 Jun 15:45
Compare
Choose a tag to compare

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

2.0.4

01 Jun 20:52
Compare
Choose a tag to compare

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'.