This repository has been archived by the owner on Feb 14, 2023. It is now read-only.
Releases: CharlesStover/reactn
Releases Β· CharlesStover/reactn
2.2.7
2.2.6
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
. π’
- Deprecated unit tests for non-latest versions of React, because they do not support asynchronous
2.2.1 - 2.2.5
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
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 toawait
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
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 aProvider
in versions of React >=16.3 <16.6.
Miscellaneous
-
Upgraded
react-testing-library
to@testing-library/react
. -
Added documentation for
useDispatch
anduseGlobal
to the README.
2.1.5
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 inreactn/default
'sReducers
interface. #105- Thanks @MikeMeyers2504!
2.1.3
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);
- This behavior is analogous to React's native
Miscellaneous
- A TypeScript
PropertyDispatcher
type has been added toreactn/types/dispatcher
, referencing a dispatcher that can be destructured.
2.1.2
2.1.1
New Features β¨
- Allows you to specify a global state property name when using
useDispatch
with a function. This behaves closely to how React's nativeuseReducer
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 includedispatch
in 2.x. #87 (Thanks @yezyilomo!) - Added ReactN DevTools to documentation. #80
2.0.4
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
andsetter
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.
- Both now accept the
- 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 noProvider
. #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'
.