![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
reason-react-update
Advanced tools
useReducer with updates and side effects!
$ yarn add reason-react-update
or
$ npm install --save reason-react-update
Then add reason-react-update
to your bsconfig.json
bs-dependencies
field.
type state = int;
type action =
| Increment
| Decrement;
[@react.component]
let make = () => {
let (state, send) =
ReactUpdate.useReducer(0, (action, state) =>
switch (action) {
| Increment => Update(state + 1)
| Decrement => Update(state - 1)
}
);
<div>
{state->Js.String.make->React.string}
<button onClick={_ => send(Decrement)}> "-"->React.string </button>
<button onClick={_ => send(Increment)}> "+"->React.string </button>
</div>;
};
If you'd rather initialize state lazily (if there's so computation you don't want executed at every render for instance), use useReducerWithMapState
where the first argument is a function taking unit
and returning the initial state.
type state = int;
type action =
| Increment
| Decrement;
[@react.component]
let make = () => {
let (state, send) =
ReactUpdate.useReducerWithMapState(
() => 0,
(action, state) =>
switch (action) {
| Increment => Update(state + 1)
| Decrement => Update(state + 1)
}
);
<div>
{state->Js.String.make->React.string}
<button onClick={_ => send(Decrement)}> "-"->React.string </button>
<button onClick={_ => send(Increment)}> "+"->React.string </button>
</div>;
};
The callback you pass to SideEffects
& UpdateWithSideEffect
returns an option(unit => unit)
, which is the cancellation function.
// doesn't cancel
SideEffects(({send}) => {
Js.log(1);
None
});
// cancels
SideEffects(({send}) => {
let request = Request.make();
request->Future.get(payload => send(Receive(payload)))
Some(() => {
Request.cancel(request)
})
});
If you want to copy/paste old reducers that don't support cancellation, you can use ReactUpdateLegacy
instead in place of ReactUpdate
. Its SideEffects
and UpdateWithSideEffects
functions accept functions that return unit
.
FAQs
> useReducer with updates and side effects!
We found that reason-react-update demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.