Skip to content

Instantly share code, notes, and snippets.

@BrianCodeItUp
BrianCodeItUp / connect.js
Last active August 27, 2020 07:12
custom react-redux connect using hook
import { useSelector, useDispatch } from 'react-redux'
function connect(mapStateToProps, mapDispatchToProps) {
return Component => {
const Wrapper = props => {
const seletedState = useSelector(state => mapStateToProps(state, props));
const dispatch = useDispatch();
const boundDispatch = mapDispatchToProps(dispatch, props);
return <Component {...seletedState} {...boundDispatch} {...props} />;
};
@BrianCodeItUp
BrianCodeItUp / component.tsx
Last active May 12, 2022 06:43
useContext, useReducer with typescript
import React from 'react';
import { View, Text, Button } from 'react-native';
import styles from './styles'
import { ContextProvider, Context } from './context';
const Compo = () => {
const { type } = useContext(Context);
return (
<View style={styles.container}>
<Text>{type}</Text>