Skip to content

Commit

Permalink
Merge pull request #46 from mediamonks/develop
Browse files Browse the repository at this point in the history
Update lifecycle
  • Loading branch information
tommymm authored Apr 12, 2022
2 parents 0802c88 + 572ab14 commit 3bcbe56
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mediamonks/react-redux-component-init",
"version": "2.0.2",
"version": "2.0.0",
"description": "A library to manage async component initialization in isomorphic React/Redux applications with server-side rendering",
"main": "./lib/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/actions/initComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default (Component, initValues, prepareKey, { caller } = {}) => (dispatch
// mounted on the client (after first render)
initSelf !== INIT_SELF_NEVER;
break;
case 'getDerivedStateFromProps':
case 'didUpdate':
errorNotPrepared = false;
shouldCallInitAction = !!initAction;
shouldCallInitActionClient = !!initActionClient;
Expand Down
14 changes: 9 additions & 5 deletions src/withInitAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,27 @@ export default (p1, p2, p3) => {
__componentInitState: { selfInitState },
} = newProps;
if (selfInitState) {
this.setState(() => ({
return {
initializedOnce: true,
}));
};
}

return null;
}

componentDidUpdate(prevProps) {
if (initProps.length && reinitialize) {
const {
__componentInitState: { initValues },
__initComponent,
} = this.props;
} = [prevProps];
const {
__componentInitState: { initValues: newInitValues, prepareKey },
} = newProps;
} = this.props;

if (initValues !== newInitValues) {
__initComponent(newInitValues, prepareKey, {
caller: 'getDerivedStateFromProps',
caller: 'didUpdate',
}).catch(this.handleInitError);
}
}
Expand Down

0 comments on commit 3bcbe56

Please sign in to comment.