Skip to content

Instantly share code, notes, and snippets.

View jake-daniels's full-sized avatar

Jakub Šoltés jake-daniels

  • Brno, Czech republic
View GitHub Profile
function initRedux(reducer, initialState) {
const StateContext = React.createContext(null)
const DispatchContext = React.createContext(null)
function Provider(props) {
const [appState, dispatch] = React.useReducer(reducer, initialState)
return (
<StateContext.Provider value={appState}>
<DispatchContext.Provider value={dispatch}>
{props.children}
const actions = Object.keys(actionMap).reduce((acc, key) => {
const actionCreator = actionMap[key]
const fn = (...args) => {
const action = actionCreator(...args)
dispatch(action)
}
return { ...acc, [key]: fn }
}, {})
function initRedux(reducer, initialState) {
const StateContext = React.createContext(null)
const DispatchContext = React.createContext(null)
function Provider(props) {
const [appState, dispatch] = React.useReducer(reducer, initialState)
return (
<StateContext.Provider value={appState}>
<DispatchContext.Provider value={dispatch}>
{props.children}
@jake-daniels
jake-daniels / Table.jsx
Last active May 4, 2018 15:01
Table component with nested components.
class Table extends React.Component {
Head = () => {
return (
<div className='head'>
</div>
)
}
Body = () => {
@jake-daniels
jake-daniels / Table.jsx
Last active May 4, 2018 15:00
Table component with single render method.
class Table extends React.Component {
render () {
return (
<div className='table'>
<div className='head'>
</div>
<div className='body'>
{this.props.items.map((item, index) => (