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 PropTypes from 'prop-types'
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
|
|
||||||
export const mapStateToProps = state => ({
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
export const mapDispatchToProps = {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ${1:hocComponentName} = (WrappedComponent) => {
|
export const ${1:hocComponentName} = (WrappedComponent) => {
|
||||||
const hocComponent = ({ ...props }) => <WrappedComponent {...props} />
|
const hocComponent = (props) => <WrappedComponent {...props} />
|
||||||
|
|
||||||
hocComponent.propTypes = {
|
hocComponent.propTypes = {
|
||||||
}
|
}
|
||||||
|
@ -26,4 +18,12 @@ export const ${1:hocComponentName} = (WrappedComponent) => {
|
||||||
return hocComponent
|
return hocComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state, ownProps) => ({
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch, ownProps) => ({
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
export default WrapperComponent => connect(mapStateToProps, mapDispatchToProps)(${1:hocComponentName}(WrapperComponent))
|
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}})
|
export default connect(mapStateToProps, mapDispatchToProps)(${1:${TM_FILENAME_BASE}})
|
|
@ -5,10 +5,16 @@
|
||||||
# key: reduxmap
|
# key: reduxmap
|
||||||
# --
|
# --
|
||||||
|
|
||||||
const mapStateToProps = (state) => ({
|
const mapStateToProps = (state, ownProps) => ({
|
||||||
${1}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
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() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
<Text> ${2:textInComponent} </Text>
|
<Text>${2:textInComponent}</Text>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state) => ({
|
const mapStateToProps = (state, ownProps) => ({
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const mapDispatchToProps = {
|
const mapDispatchToProps = (dispatch, ownProps) => ({
|
||||||
|
|
||||||
}
|
})
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(${1:${TM_FILENAME_BASE}})
|
export default connect(mapStateToProps, mapDispatchToProps)(${1:${TM_FILENAME_BASE}})
|
|
@ -11,11 +11,10 @@ const initialState = {
|
||||||
|
|
||||||
export default (state = initialState, { type, payload }) => {
|
export default (state = initialState, { type, payload }) => {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case ${1:typeName}:
|
||||||
|
return { ...state, ...payload }
|
||||||
|
|
||||||
case ${1:typeName}:
|
default:
|
||||||
return { ...state, ...payload }
|
return state
|
||||||
|
|
||||||
default:
|
|
||||||
return state
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue