Skip to content

Instantly share code, notes, and snippets.

@defint
Created August 7, 2020 11:43
Show Gist options
  • Save defint/fcf383dda69a934bfa411c2b89b72bc4 to your computer and use it in GitHub Desktop.
Save defint/fcf383dda69a934bfa411c2b89b72bc4 to your computer and use it in GitHub Desktop.
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