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 { useEffect, useReducer } from "react"; | |
| import { todoReducer } from "../08-useReducer/todoReducer"; | |
| const initialState = [] | |
| const init = () => { | |
| return JSON.parse(localStorage.getItem('todos')) || []; | |
| } | |
| export const useTodo = () => { |
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 } from 'react'; | |
| export const useForm = ( initialForm = {}) => { | |
| const [formState, setFormState] = useState( initialForm ) | |
| const onInputChange = ({ target}) => { | |
| const { name, value } = target; | |
| setFormState({ | |
| ...formState, |
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 { useEffect, useState } from "react" | |
| export const useFetch = ( url ) => { | |
| const [state, setState] = useState({ | |
| data: null, | |
| loading: true, | |
| hasError: 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 { useState } from "react" | |
| export const useCounter = (initialValue = 10) => { | |
| const [ counter, setCounter ] = useState(initialValue) | |
| const increment = ( value = 1 ) => { | |
| setCounter( counter + value ) | |
| } |