Skip to content

v2.0.3

Compare
Choose a tag to compare
@thedevelobear thedevelobear released this 28 Mar 16:04
· 5 commits to master since this release
98adb14

Fix useRewards hook that didn't work with async components.

Here's an example of the code that didn't work in v2.0.0/v2.0.1/v2.0.2:

const SomeAsyncScreen = () => {
  const [ data, setData ] = useState(undefined);
  const { reward, isAnimating } = useReward("rewardId", "confetti");

  useEffect(() => {
    setTimeout(() => {
      setData({});
    }, 500);
  }, []);

  if (!data) return "Loading...";

  return (
    <div className="App">
      <span id="rewardId" /> 
      <button disabled={isAnimating} onClick={reward}>
        Make it rain!
      </button>
    </div>
  );
};

The problem was that the element was grabbed in useLayoutEffect, which fired synchronously after all DOM mutations. In this case there was no element with an id === "rewardId" on mount.

The problem was fixed in this release.