-
-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds support for getDerivedStateFromProps
#63
Adds support for getDerivedStateFromProps
#63
Conversation
…alled and that it takes precedence over `componentWillMount`
src/index.js
Outdated
@@ -73,7 +73,8 @@ function renderToString(vnode, context, opts, inner, isSvgMode) { | |||
c._disable = c.__x = true; | |||
c.props = props; | |||
c.context = context; | |||
if (c.componentWillMount) c.componentWillMount(); | |||
if (c.constructor.getDerivedStateFromProps) c.state = assign(assign({}, c.state), c.constructor.getDerivedStateFromProps(c.props, c.state)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c.constructor
here can be nodeName
, saves a few bytes and a lookup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@developit done
Build "preactRenderToString" to dist:
1.44 kB: index.mjs
1.49 kB: index.js
Awesome! It's released as 4.1.0! |
Noting bundle size change
|
* Adds support for `getDerivedStateFromProps` * Adding tests to verify that `getDerivedStateFromProps` is correctly called and that it takes precedence over `componentWillMount` * changing `c.constructor` reference to `nodeName` to save a few bytes and a lookup per preactjs/preact-render-to-string#63 (comment)
Addresses Issue #62 by adding support for
getDerivedStateFromProps
which takes precedence overcomponentWillMount
.npm run build
(Before)npm run build
(After)Support was added to Preact with this PR preactjs/preact#1094