This file contains hidden or 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 { fetchingTodos } from "store/features/todos"; | |
| interface Props { | |
| data: ITodoState; | |
| fetchingTodos: () => void; | |
| } |
This file contains hidden or 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
| ... | |
| extraReducers: builder=> { | |
| builder.addCase(fetchingTodos.fulfilled, (state, {payload}) => { | |
| // you could do something with payload data before add it to store. | |
| }) | |
| builder.addCase(fetchingTodos.rejected, (state, {payload}) => { | |
| // you could do something with payload data before add it to store. | |
| }) | |
| } |
This file contains hidden or 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 { createSlice } from '@reduxjs/toolkit' | |
| import { fetchingTodos } from './todos-actions' | |
| const { actions, reducer } = createSlice({ | |
| initialState, | |
| name: "todos", | |
| reducers: { | |
| fetchingStart: (state) => ({ ...state, fetching: true }), //<< THIS IS REDUNDANT | |
| }, |
This file contains hidden or 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 { createAsyncThunk } from '@reduxjs/toolkit' | |
| import IState, { ITodo, AppDispatch } from './types'; //<<--------ADDED | |
| /** | |
| * fetching all todos | |
| * | |
| */ | |
| export const fetchingTodos = createAsyncThunk( | |
| 'todos/fetchingTodos', | |
| async() => { | |
| const res = await fetch('https://jsonplaceholder.typicode.com/todos'); |
This file contains hidden or 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 { createSlice, createAsyncThunk } from "@reduxjs/toolkit"; | |
| import IStore, { ITodoState } from './types' | |
| const initialState: ITodoState = { | |
| fetching: false, | |
| todos: [], | |
| error: null, | |
| }; |
This file contains hidden or 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 { combineReducers } from "@reduxjs/toolkit"; | |
| import todosReducer from "./todos"; | |
| export default combineReducers({ | |
| todos: todosReducer, | |
| }); |
This file contains hidden or 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 { configureStore, getDefaultMiddleware } from "@reduxjs/toolkit"; | |
| import { createLogger } from "redux-logger"; | |
| import rootReducer from "./features"; | |
| const store = configureStore({ | |
| reducer: rootReducer, | |
| devTools: true, | |
| middleware: getDefaultMiddleware().concat([createLogger()]), | |
| }); |
This file contains hidden or 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
| void main() async { | |
| //listen(); | |
| //mapResults(); | |
| // handleError(); | |
| } | |
| Stream<int> get() async* { | |
| for (var i = 1; i <= 4; i++) { | |
| yield i; | |
| yield i; |
This file contains hidden or 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, { FC, useState, ChangeEvent, FormEvent } from 'react' | |
| type E = ChangeEvent<HTMLInputElement> | FormEvent<HTMLInputElement> | |
| interface iOwnProps {} | |
| const NameFields: FC<iOwnProps> = props => { | |
| const name = useInputField('') | |
| const firstName = useInputField('') | |
| return ( |
This file contains hidden or 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, {createContext, useContext } from 'react' | |
| const NumberContext = createContext() | |
| function NumberProvider(props){ | |
| const [number, setNumber]= useState(0) | |
| return ( | |
| <NumberContext.Provider value={number}> | |
| <NumberContent /> |
NewerOlder