React-Redux provides hooks API
with nice abstraction.
Especially, useSelector is probaly less misused than mapStateToProps.
is a library for global state without Redux.
This library provides almost compatible hooks API to React-Redux.
It’s developed with performance in mind, and it should
be as performant as React-Redux, even though it utilizes
only React context. See the GitHub repo for more information.
This post shows benchmark results to convince that
it actually is performant in one scenario.
It’s worth mentioning that react-tracked, as the name implies,
has another useTrackedState hook that has capability of
state usage tracking. Unlike useSelector, developers don’t need
to define selectors for this hook.
It’s also worth mentioning that another library
provides the useTrackedState hook for Redux.
See the GitHub repo for more information.
We compare all hooks described above.
To benchmark different frameworks,
Checkout the forked repo
if you want to reproduce the benchmark result at your end.
react-tracked-useTrackedState: useTrackedState in react-tracked v0.4.0
react-tracked-useSelector: useSelector in react-tracked v0.4.0
reactive-react-redux-useTrackedState: useTrackedState in reactive-react-redux v4.0.0-beta.0
reactive-react-redux-useSelector: useSelector in reactive-react-redux v4.0.0-beta.0
react-redux-hooks: useSelector in react-redux v7.1.0
The benchmark code for useSelector is almost identical
among three libraries.
The code for useTrackedState is also identical
between two libraries.
However, the code for useSelector and
the code for useTrackedState is a bit different
and they are optimized separately.
Hence, be reminded when comparing with different hooks.
I hope these results encourage developers to try my two libraries.
The post Redux-less context-based useSelector hook that has same performance as React-Redux appeared first on Web Design Tips.
Best Web Design Myrtle Beach
Website Design Myrtle Beach
Web Design Myrtle Beach