Improve some Redux snippets
This commit is contained in:
parent
52f2eb5a47
commit
d76f3afdf2
|
@ -9,16 +9,8 @@ import React from 'react'
|
|||
import PropTypes from 'prop-types'
|
||||
import { connect } from 'react-redux'
|
||||
|
||||
export const mapStateToProps = state => ({
|
||||
|
||||
})
|
||||
|
||||
export const mapDispatchToProps = {
|
||||
|
||||
}
|
||||
|
||||
export const ${1:hocComponentName} = (WrappedComponent) => {
|
||||
const hocComponent = ({ ...props }) => <WrappedComponent {...props} />
|
||||
const hocComponent = (props) => <WrappedComponent {...props} />
|
||||
|
||||
hocComponent.propTypes = {
|
||||
}
|
||||
|
@ -26,4 +18,12 @@ export const ${1:hocComponentName} = (WrappedComponent) => {
|
|||
return hocComponent
|
||||
}
|
||||
|
||||
const mapStateToProps = (state, ownProps) => ({
|
||||
|
||||
})
|
||||
|
||||
const mapDispatchToProps = (dispatch, ownProps) => ({
|
||||
|
||||
})
|
||||
|
||||
export default WrapperComponent => connect(mapStateToProps, mapDispatchToProps)(${1:hocComponentName}(WrapperComponent))
|
|
@ -23,12 +23,12 @@ export class ${1:${TM_FILENAME_BASE}} extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
const mapStateToProps = (state, ownProps) => ({
|
||||
|
||||
})
|
||||
|
||||
const mapDispatchToProps = {
|
||||
const mapDispatchToProps = (dispatch, ownProps) => ({
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(${1:${TM_FILENAME_BASE}})
|
|
@ -5,10 +5,16 @@
|
|||
# key: reduxmap
|
||||
# --
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
${1}
|
||||
const mapStateToProps = (state, ownProps) => ({
|
||||
|
||||
})
|
||||
|
||||
const mapDispatchToProps = {
|
||||
|
||||
}
|
||||
const mapDispatchToProps = (dispatch, ownProps) => ({
|
||||
|
||||
})
|
||||
|
||||
const mergeProps = (stateProps, dispatchProps, ownProps) => ({
|
||||
...ownProps,
|
||||
...dispatchProps,
|
||||
...stateProps,
|
||||
})
|
|
@ -18,18 +18,18 @@ export class ${1:${TM_FILENAME_BASE}} extends Component {
|
|||
render() {
|
||||
return (
|
||||
<View>
|
||||
<Text> ${2:textInComponent} </Text>
|
||||
<Text>${2:textInComponent}</Text>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
|
||||
const mapStateToProps = (state, ownProps) => ({
|
||||
|
||||
})
|
||||
|
||||
const mapDispatchToProps = {
|
||||
|
||||
}
|
||||
const mapDispatchToProps = (dispatch, ownProps) => ({
|
||||
|
||||
})
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(${1:${TM_FILENAME_BASE}})
|
|
@ -11,11 +11,10 @@ const initialState = {
|
|||
|
||||
export default (state = initialState, { type, payload }) => {
|
||||
switch (type) {
|
||||
case ${1:typeName}:
|
||||
return { ...state, ...payload }
|
||||
|
||||
case ${1:typeName}:
|
||||
return { ...state, ...payload }
|
||||
|
||||
default:
|
||||
return state
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue