Improve some Redux snippets

This commit is contained in:
Seong Yong-ju 2019-12-25 22:46:48 +09:00
parent 52f2eb5a47
commit d76f3afdf2
5 changed files with 33 additions and 28 deletions

View File

@ -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))

View File

@ -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}})

View File

@ -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,
})

View File

@ -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}})

View File

@ -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
}
}