Created
August 7, 2020 11:43
-
-
Save defint/fcf383dda69a934bfa411c2b89b72bc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useEffect} from 'react'; | |
import {declareAction, declareAtom} from "@reatom/core"; | |
import {useAction, useAtom} from "@reatom/react"; | |
const changeAtom = declareAction(); | |
const atomPrimitive = declareAtom(0, on => [ | |
on(changeAtom, (state, payload) => { | |
console.log("new payload: ", payload); | |
return payload; | |
}) | |
]); | |
export const App = () => { | |
const changeValue = useAction(changeAtom); | |
const value = useAtom(atomPrimitive); | |
useEffect(() => { | |
setInterval(() => { | |
document.getElementsByTagName('button')[0].click(); | |
}, 1000); | |
}, []); | |
return ( | |
<div> | |
<div>{value}</div> | |
<button onClick={() => { | |
changeValue(Math.random()); | |
}}>Update manual</button> | |
</div> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment