Skip to content

Instantly share code, notes, and snippets.

@clucasalcantara
Last active April 3, 2018 09:33
Show Gist options
  • Save clucasalcantara/fdbc52cdfdc0ceb9031f50f55496c52d to your computer and use it in GitHub Desktop.
Save clucasalcantara/fdbc52cdfdc0ceb9031f50f55496c52d to your computer and use it in GitHub Desktop.
render props pattern examples
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import './App.css'
class CounterWrapper extends Component {
state = {
count: 0,
}
increment = () => {
const { count } = this.state
return this.setState({ count: count + 1 })
}
decrement = () => {
const { count } = this.state
return this.setState({ count: count - 1 })
}
render() {
const { render } = this.props
const { count } = this.state
return (
<div className="App">
{
render({
increment: this.increment,
decrement: this.decrement,
count: count
})
}
</div>
)
}
}
CounterWrapper.propTypes = {
render: PropTypes.func.isRequired,
}
export default CounterWrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment