Commit 901e95bb authored by Robert Knight's avatar Robert Knight

Use `useLayoutEffect` rather than `useEffect` to subscribe to store

This fixes a potential issue where the component would not be re-rendered if a
store update occurred in between the initial rendering and `useEffect`
subsequently firing.
parent 8ce09869
import { useEffect, useRef, useReducer } from 'preact/hooks';
import { useLayoutEffect, useRef, useReducer } from 'preact/hooks';
/**
* Result of a cached store selector method call.
......@@ -129,7 +129,7 @@ export function useStore(store) {
// Register a subscriber which clears cache and re-renders component when
// relevant store state changes.
useEffect(() => {
useLayoutEffect(() => {
const cleanup = store.subscribe(() => {
const invalidEntry = cache.find(
// nb. A potential problem here is that the method arguments may refer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment