React hooks

Evt let you work with events in react without having to worry about cleaning up afterward.

useEvt()

import { useState } from "react";
import { Evt } from "evt";
import { useEvt } from "evt/hooks";

const evtTick = Evt.create();

setInterval(()=> evtTick.post(), 1000);

function App(){

    const [count, setCount]= useState(0);

    useEvt(ctx=> {
    
        evtTick.attach(ctx, ()=> setCount(count+1));
    
    },[count]);
    
    return <h1>tick count: {count}</h1>;

}

Run it

useRerenderOnStateChange()

ESLint

You can use this react-hooks/exhaustive-deps to be warned if you forget a dependency:

Last updated