use-nodecg
This package is a collection custom hooks of React Hooks for NodeCG API.
🚨 This package is in alpha state, as well as the React Hooks API itself. Do not use in production. But feel free to try out and file an issue for suggestion/bugs!
Install
npm install use-nodecg@next# or yarn add use-nodecg@next
About React Hooks
The React Hooks are a new way of sharing code between components, introduced in version 16.8.
Please read the documentation of React Hooks thoroughly before using them.
It also helps to learn the background mechanism of React Hooks. React hooks: not magic, just arrays
Recommendation
Use eslint-plugin-react-hooks in your project. It is 100% smarter than you to detect violation of the Rules of Hooks.
Usage
useReplicant
- Subscribes to specified replicant and returns the value as state.
- Allows you to use replicant values in function component.
; // This component will re-render when the `counter replicant value changes
useReplicantOnce
- Reads specified replicant value once, without subscribing to it.
- Uses
readReplicant
internally. - Returns single value that will be updated once when it reads the value
- Does NOT subscribe to replicant value changes
; // Only reads the replicant value once and doesn't update
useListenFor
- Subscribes messages with
listenFor
, and unlistens on unmount. - Combining with other hooks enables powerful stateful features with function component
; // Shows modal for 1 second when NodeCG receives 'errorHappened' message from the server
License
MIT © Keiichiro Amemiya (Hoishin)