Skip to content

Instantly share code, notes, and snippets.

@vzaidman
Last active May 7, 2019 08:16
Show Gist options
  • Save vzaidman/7839b1a5439f3aa99d3446cd2995f4bd to your computer and use it in GitHub Desktop.
Save vzaidman/7839b1a5439f3aa99d3446cd2995f4bd to your computer and use it in GitHub Desktop.
import { makeThunkAsyncActionCreator } from 'redux-toolbelt-thunk'
import { fetchTodosFromServer } from './api'
export const fetchTodos = makeThunkAsyncActionCreator('FETCH_TODOS', fetchTodosFromServer)
import { makeAsyncReducer } from 'redux-toolbelt'
import { fetchTodos } from './actions'
export const todos = makeAsyncReducer(fetchTodos)
import React from 'react'
import { connect } from 'react-redux'
import * as actions from './actions'
const Main = ({ fetchTodos, todos }) => (
<div>
<button onClick={fetchTodos}> Refresh </button>
{todos.loading && (
<span> loading.. </span>
)}
{todos.data && (
<TodoList todos={todos.data}/>
)}
</div>
)
export default connect(
state => ({ todos: state.todos }),
{ fetchTodos: actions.fetchTodos }
)(Main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment