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

remove call nothisAll(this) #3

Closed
joelnet opened this issue Aug 10, 2018 · 1 comment
Closed

remove call nothisAll(this) #3

joelnet opened this issue Aug 10, 2018 · 1 comment

Comments

@joelnet
Copy link
Owner

joelnet commented Aug 10, 2018

nothisAll(this) is not a complete eradication. It's actually the opposite as it adds a reference to this. This is contrary to the intent of the library.

Find another way.

@joelnet
Copy link
Owner Author

joelnet commented Aug 13, 2018

package https://www.npmjs.com/package/nothis-react has been created to solve this. Code can now be written like:

import React from 'react'
import NoThis from 'nothis-react'
 
class Counter extends NoThis.Component {
  state = { count: 0 }
 
  increment({ setState }) {
    setState(({ count }) => ({ count: count + 1 }))
  }
 
  render({ increment, state: { count } }) {
    return (
      <div>
        <button onClick={increment}>{count}</button>
      </div>
    )
  }
}

@joelnet joelnet closed this as completed Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant