Skip to content

Commit bbc5c98

Browse files
committed
fix: read parent state from prototype in useThru to avoid StrictMode double-apply
1 parent a0d485c commit bbc5c98

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/control.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ export function controlEqual(prev, next) {
8484

8585
export function useThru(control, interceptor) {
8686
const ctrl = useNewControl(control);
87-
const {state, useState} = ctrl;
88-
if (Object.getPrototypeOf(ctrl).state) {
89-
ctrl.state = interceptor(state);
87+
const parentState = Object.getPrototypeOf(ctrl).state;
88+
if (parentState) {
89+
ctrl.state = interceptor(parentState);
9090
} else {
91+
const {useState} = ctrl;
9192
ctrl.useState = (...params) => interceptor(useState(...params));
9293
}
9394
return ctrl;

0 commit comments

Comments
 (0)