Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dependencies/useStoreDependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ function useStoreDependency<Props, DepType>(
): DepType {
enforceDispatcher(dispatcher);

const [dependencyValue, setDependencyValue] = useState({
const [dependencyValue, setDependencyValue] = useState(() => ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is 💯 !

The only other tweak we could consider is literally moving the const newValue = { dependency: ... } up above here, then reusing newValue both as the initial state and where it is already used. That has the added benefit of skipping an extra eval of the deref in the opposite case (where we are initializing state for the first time)

dependency: calculate(dependency, props),
});
}));

const currProps = useCurrent(props);

Expand Down