Skip to content

Commit d76f3af

Browse files
committed
Improve some Redux snippets
1 parent 52f2eb5 commit d76f3af

File tree

5 files changed

+33
-28
lines changed

5 files changed

+33
-28
lines changed

snippets/rjsx-mode/Redux/hocredux

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ import React from 'react'
99
import PropTypes from 'prop-types'
1010
import { connect } from 'react-redux'
1111

12-
export const mapStateToProps = state => ({
13-
14-
})
15-
16-
export const mapDispatchToProps = {
17-
18-
}
19-
2012
export const ${1:hocComponentName} = (WrappedComponent) => {
21-
const hocComponent = ({ ...props }) => <WrappedComponent {...props} />
13+
const hocComponent = (props) => <WrappedComponent {...props} />
2214

2315
hocComponent.propTypes = {
2416
}
2517

2618
return hocComponent
2719
}
2820

21+
const mapStateToProps = (state, ownProps) => ({
22+
23+
})
24+
25+
const mapDispatchToProps = (dispatch, ownProps) => ({
26+
27+
})
28+
2929
export default WrapperComponent => connect(mapStateToProps, mapDispatchToProps)(${1:hocComponentName}(WrapperComponent))

snippets/rjsx-mode/Redux/rcredux

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ export class ${1:${TM_FILENAME_BASE}} extends Component {
2323
}
2424
}
2525

26-
const mapStateToProps = (state) => ({
26+
const mapStateToProps = (state, ownProps) => ({
2727

2828
})
2929

30-
const mapDispatchToProps = {
30+
const mapDispatchToProps = (dispatch, ownProps) => ({
3131

32-
}
32+
})
3333

3434
export default connect(mapStateToProps, mapDispatchToProps)(${1:${TM_FILENAME_BASE}})

snippets/rjsx-mode/Redux/reduxmap

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
# key: reduxmap
66
# --
77

8-
const mapStateToProps = (state) => ({
9-
${1}
8+
const mapStateToProps = (state, ownProps) => ({
9+
10+
})
11+
12+
const mapDispatchToProps = (dispatch, ownProps) => ({
13+
1014
})
1115

12-
const mapDispatchToProps = {
13-
14-
}
16+
const mergeProps = (stateProps, dispatchProps, ownProps) => ({
17+
...ownProps,
18+
...dispatchProps,
19+
...stateProps,
20+
})

snippets/rjsx-mode/Redux/rncredux

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ export class ${1:${TM_FILENAME_BASE}} extends Component {
1818
render() {
1919
return (
2020
<View>
21-
<Text> ${2:textInComponent} </Text>
21+
<Text>${2:textInComponent}</Text>
2222
</View>
2323
)
2424
}
2525
}
2626

27-
const mapStateToProps = (state) => ({
28-
27+
const mapStateToProps = (state, ownProps) => ({
28+
2929
})
3030

31-
const mapDispatchToProps = {
32-
33-
}
31+
const mapDispatchToProps = (dispatch, ownProps) => ({
32+
33+
})
3434

3535
export default connect(mapStateToProps, mapDispatchToProps)(${1:${TM_FILENAME_BASE}})

snippets/rjsx-mode/Redux/rxreducer

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ const initialState = {
1111

1212
export default (state = initialState, { type, payload }) => {
1313
switch (type) {
14+
case ${1:typeName}:
15+
return { ...state, ...payload }
1416

15-
case ${1:typeName}:
16-
return { ...state, ...payload }
17-
18-
default:
19-
return state
17+
default:
18+
return state
2019
}
2120
}

0 commit comments

Comments
 (0)