Skip to content
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

Use React.PureComponent instead of pure-render-decorator #144

Closed
adidahiya opened this issue Nov 14, 2016 · 4 comments
Closed

Use React.PureComponent instead of pure-render-decorator #144

adidahiya opened this issue Nov 14, 2016 · 4 comments

Comments

@adidahiya
Copy link
Contributor

adidahiya commented Nov 14, 2016

docs: https://facebook.github.io/react/docs/react-api.html#react.purecomponent

  • it is just as usable as the decorator; you can override shouldComponentUpdate to opt out of pure rendering
  • this reduces complexity by removing 2 dependencies (decorator + its typings)
  • this will require rewriting the tslint rule which enforces pure components this seems to have gotten lost somewhere in the last few months...
  • 🔥 requires a react dependency of >= 15.3.0
@jkillian
Copy link
Contributor

just in case it helps, here's the ruby script I used to make this change in our codebase. (Note that it isn't designed to be robust, it might not work in cases with multiple decorators, etc.) You want to run it in your root src directory.

files = Dir['**/*.{ts,tsx}']
files.each do |f|
    lines = File.readlines(f)
    lines.delete_if { |line| line =~ /import|require/ && line =~ /pure-render-decorator/ }
    # remove line with decorator, change if you use a different import name
    while decorator_index = lines.find_index { |line| line =~ /@PureRender/ }
        lines[decorator_index + 1].sub!(/Component</, 'PureComponent<')
        lines.delete_at(decorator_index)
    end
    File.write(f, lines.join(''))
end

Also, doing this means the peerDependencies on React will have to be bumped to ^15.3.0 or something similar. It might be prudent to hold off for a little on doing this to not force people to upgrade React

@giladgray
Copy link
Contributor

🔥 breaking change because it requires React >= 15.3!

@giladgray giladgray added this to the 2.x milestone Jan 3, 2017
@giladgray giladgray modified the milestones: 2.x, 2.0.0 Jul 13, 2017
@betalb
Copy link

betalb commented Nov 13, 2017

In package.json react requirement is already >= 15.5.1, is this still beraking change?

@adidahiya
Copy link
Contributor Author

@betalb no, the peerDependency still includes react v0.14 and will stay that way until blueprint core 2.0:

"react": "^16.0.0 || ^15.0.1 || ^0.14",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants