Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-stoian-lgp committed Dec 13, 2024
1 parent d745eb0 commit 7898ad8
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions internal/SharedStateDecorator/SharedStateDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ const SharedStateDecorator = hoc(defaultConfig, (config, Wrapped) => {
// eslint-disable-next-line no-shadow
const SharedStateDecorator = (props) => {
const context = useContext(SharedState);
let data = useRef({});
let [, setUpdateOnMountState] = useState(false);
const data = useRef({});
// eslint-disable-next-line no-unused-vars
const [updateOnMountState, setUpdateOnMountState] = useState(false);

const isUpdatable = () => {
const {[idProp]: id, noSharedState} = props;
Expand Down Expand Up @@ -97,21 +98,24 @@ const SharedStateDecorator = hoc(defaultConfig, (config, Wrapped) => {
}
}, [context, props]);

let sharedState = initSharedState();
const prevNoSharedState = useRef(props.noSharedState);
const sharedState = initSharedState();
const prevProps = useRef();

useEffect(() => {
loadFromContext();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [loadFromContext]);

useEffect(() => {
if (!prevNoSharedState && props.noSharedState) {
data.current = {};
} else if (prevNoSharedState && !props.noSharedState) {
loadFromContext();
if (prevProps.current && prevProps.current.noSharedState !== props.noSharedState) {
if (!prevProps.noSharedState && props.noSharedState) {
data.current = {};

Check warning on line 111 in internal/SharedStateDecorator/SharedStateDecorator.js

View check run for this annotation

Codecov / codecov/patch

internal/SharedStateDecorator/SharedStateDecorator.js#L111

Added line #L111 was not covered by tests
} else if (prevProps.noSharedState && !props.noSharedState) {
loadFromContext();

Check warning on line 113 in internal/SharedStateDecorator/SharedStateDecorator.js

View check run for this annotation

Codecov / codecov/patch

internal/SharedStateDecorator/SharedStateDecorator.js#L113

Added line #L113 was not covered by tests
}
}
}, [props.noSharedState, loadFromContext]);

prevProps.current = props;
}, [loadFromContext, props]);

const {...wrappedComponentProps} = props;
delete wrappedComponentProps.noSharedState;
Expand Down

0 comments on commit 7898ad8

Please sign in to comment.