Last active
May 7, 2019 08:16
-
-
Save vzaidman/7839b1a5439f3aa99d3446cd2995f4bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { makeThunkAsyncActionCreator } from 'redux-toolbelt-thunk' | |
import { fetchTodosFromServer } from './api' | |
export const fetchTodos = makeThunkAsyncActionCreator('FETCH_TODOS', fetchTodosFromServer) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { makeAsyncReducer } from 'redux-toolbelt' | |
import { fetchTodos } from './actions' | |
export const todos = makeAsyncReducer(fetchTodos) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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