1.0.1 • Published 6 years ago
@hqro/conduct v1.0.1
Conduct
Replacing redux with the new React context API
How to use ?
yarn add @hqro/conduct
// src/index.js
import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'conduct'
import './index.css'
import App from './src/containers/App'
const store = { count: 0 }
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root'),
)
// src/containers/App
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'conduct'
class App extends Component {
static propTypes = {
count: PropTypes.number,
}
static defaultProps = {
count: 0,
}
render() {
const { count } = this.props
return (
<div className="App">
<p>Count: {count}</p>
</div>
)
}
}
const mapStateToProps = state => ({
count: state.count || 0,
})
export default connect(mapStateToProps)(App)
1.0.1
6 years ago