lucialand / luciex

Simpler state management
MIT License
20 stars 0 forks source link

React Bindings #3

Open shadowtime2000 opened 3 years ago

shadowtime2000 commented 3 years ago

Possible usage:

import { Atom } from "luciex";
import { useAtom } from "luciex-react";

function Counter({ countAtom }) {
    const increment = useCallback((num) => num + 1);
    const [val, dispatch] = useAtom(countAtom);

    return (
        <>
            <div>Count: {val}</div>
            <button onClick={() => dispatch(increment)}>Increment!</button>
        </>
    )
}
aidenybai commented 3 years ago

This could work

shadowtime2000 commented 3 years ago

I could do a fake useAtom where it doesn't link at all to the actual global state and it uses it's own copy, or I could looking into subscribing forced renders.