reason-react/docs/useeffect-hook.md at main · feihong/reason-react · GitHub
Skip to content

Latest commit

 

History

History
35 lines (28 loc) · 802 Bytes

File metadata and controls

35 lines (28 loc) · 802 Bytes
title useEffect Hook

React.js docs for useEffect

Here's a simple example of how to use React's useState with useEffects.

Cleaning up an Effect

[@react.component]
let make = () => {
    React.useEffect0(() => {
        let id = subscription.subscribe();
        /* clean up the subscription */
        Some(() => subscription.unsubscribe(id));
    });
}

Conditionally Firing an Effect

With this, the subscription will only be recreated when ~source changes

[@react.component]
let make = (~source) => {
    React.useEffect1(() => {
        let id = subscription.subscribe();
        /* clean up the subscription */
        Some(() => subscription.unsubscribe(id));
    }, [|source|]);
}