Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Update to use getDerivedStateFromProps #29

Merged
merged 3 commits into from
Dec 10, 2019
Merged

Conversation

chrismllr
Copy link
Contributor

Also stores the linkifyit instance within state, instead of on the Class.

Resolves issue #27

@@ -16,15 +16,22 @@ const textPropTypes = Text.propTypes || {}
const { OS } = Platform

class Hyperlink extends Component {
static getDerivedStateFromProps(nextProps, prevState) {
if (nextProps.linkify !== prevState.linkifyIt) {
Copy link
Contributor Author

@chrismllr chrismllr Apr 26, 2018

Choose a reason for hiding this comment

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

I am not sure if this will require using a lodash.isEqual, or something of the sort, but will help as right now every time the component receives props a new instance of linkifyIt is being created

Choose a reason for hiding this comment

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

Testing this locally now, it seems this change has a problem if you do not pass in the linkify prop from outside. That will trigger a getDerivedStateFromProps where nextProps.linkify is undefined, and prevState.linkifyIt is the default value from the constructor (require('linkify-it')()), and thereby unset the state variable.

@Linoa65
Copy link

Linoa65 commented Oct 8, 2019

Some news about this PR ? React warn us about deprecated usage, this PR seems to be ok, why this is unmerged ?

@karltaylor
Copy link

Also getting this warning. Might have to patchPackage this until this is merged but would be great to get it in @obipawan

@bitcrumb
Copy link

bitcrumb commented Nov 6, 2019

@obipawan Can this PR be taken up & merged? Thanks! Seems like a reasonably sized PR ;-)

@stianjensen
Copy link

The PR has a conflict that needs to be solved, but it would be great to get this in now that the latest version of react native gives a warning for using componentWillReceiveProps.

@chrismllr
Copy link
Contributor Author

Resolved the conflicts, should be good to go 👍

@ShotSkydiver
Copy link

ShotSkydiver commented Dec 5, 2019

There actually were still a few issues with this PR's changes; running npm run build fails with a babel linting error, I've created a PR in @chrismllr's forked repo, so it can be merged into his fork and then this PR can automatically reflect my fixes!

@@ -52,10 +59,10 @@ class Hyperlink extends Component {
return typeof component.props.children !== 'string'
}

linkify(component){
linkify = (component) => {

Choose a reason for hiding this comment

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

The babel build script failed due to this change; transforming this new class property syntax requires the babel plugin proposal-class-properties, which requires Babel 7

@chrismllr
Copy link
Contributor Author

@ShotSkydiver Yeah, that makes sense. Just merged your PR into my fork

@obipawan
Copy link
Owner

Hi @chrismllr @ShotSkydiver
Thanks for the PR ❤️ 🎊
My sincere apologies to all those who've been waiting for this. I'm getting this in with the next release

@obipawan obipawan merged commit d97cf7f into obipawan:master Dec 10, 2019
@obipawan
Copy link
Owner

Available with v0.0.17 👍

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants