react-object-components

1.0.0 • Public • Published

react-object-components

Just install the package:

npm i --save react-object-components

And wrap your component objects with roc:

import roc from 'react-object-components'

const App = roc({
  data: () => ({
    count: 0,
    timer: null
  }),

  mounted() {
    this.timer = setInterval(function() {
      this.increment()
    }.bind(this), 1000)
  },

  unmount() {
    clearInterval(this.timer)
  },

  methods: {
    increment() {
      this.count = this.count + 1
    },
  },

  render() {
    return (
      <>
        {this.count}
        <Button onClick={() => this.count = this.count + 1}>inc</Button>
        <Button onClick={() => this.count = this.count - 1}>dec</Button>
      </>
    )
  }
})

const Button = roc({
  rerender(nextProps, nextState) {
    return false
  },

  render() {
    console.log("render")
    return (
      <button onClick={this.props.onClick}>{this.props.children}</button>
    )
  }
})

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
)

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.00latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.00

Package Sidebar

Install

npm i react-object-components

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

3.6 kB

Total Files

4

Last publish

Collaborators

  • desofto