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 { useState, useRef, useEffect } from 'react'; | |
| const Search: React.FC = () => { | |
| const inputRef = useRef<HTMLInputElement | null>(null); | |
| const [name, setName] = useState(''); | |
| useEffect(() => { | |
| if (!inputRef.current) { | |
| 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
| const ADD_TODO = 'add_todo'; | |
| const ADD_TODO_SUCCESS = 'add_todo_success'; | |
| const ADD_TODO_ERROR = 'add_todo_error'; | |
| const initialState = { | |
| loading: false, | |
| error: null, | |
| data: [], | |
| } |
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
| enum ActionType { | |
| ADD_TODO = 'add_todo', | |
| ADD_TODO_SUCCESS = 'add_todo_success', | |
| ADD_TODO_ERROR = 'add_todo_error', | |
| } | |
| interface TodoState { | |
| loading: boolean; | |
| error: string | null; | |
| data: string[]; |
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
| enum ActionType { | |
| ADD_TODO = 'add_todo', | |
| ADD_TODO_SUCCESS = 'add_todo_success', | |
| ADD_TODO_ERROR = 'add_todo_error', | |
| } | |
| interface TodoState { | |
| loading: boolean; | |
| error: string | null; | |
| data: string[]; |
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
| const addCount = () => ({ | |
| type: "ADD_COUNT" | |
| }); | |
| export default { | |
| addCount | |
| }; |
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 { useSelector } from 'react-redux'; | |
| const TodoList: React.FC = () => { | |
| const { todos } = useSelector((state) => state.todos); | |
| // Property 'todos' does not exist on type 'DefaultRootState'. | |
| return ( | |
| <ul> | |
| {todos.map((todo) => ( | |
| <li>{todo}</li> |
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 { useSelector } from './useSelector'; | |
| const TodoList: React.FC = () => { | |
| const { todos } = useSelector((state) => state.todos); | |
| return ( | |
| <ul> | |
| {todos.map((todo) => ( | |
| <li>{todo}</li> | |
| ))} |
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
| const joe = { | |
| update(message) { | |
| console.log(`Joe receive ${message}`); | |
| } | |
| } | |
| const jason = { | |
| update(message) { | |
| console.log(`Jayson read ${message}`); | |
| } |