WebReflection / augmentor

Extensible, general purpose, React like hooks for the masses.
https://medium.com/@WebReflection/demystifying-hooks-f55ad885609f
ISC License
134 stars 7 forks source link

Asynchronous functions lose effects #24

Closed dy closed 4 years ago

dy commented 4 years ago
import a from 'augmentor'
let f1 = a.augmentor(async () => {
  let [x, setx] = a.useState(0);
  console.log(x)
  await '';
  a.useEffect(() => {
    setx(1)
  }, [])
});

Function isn't updated here. Is that by design?

WebReflection commented 4 years ago

Yeah, that cannot work, and it wouldn't work in React neither: https://itnext.io/react-async-components-classes-vs-hooks-1a9068b61b3f

You should likely separate data behaviors from hooks logic, as described in the link I've posted.