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 arr = [ ['key', 'value'], ['x', 500] ]; | |
| const obj = Object.fromEntries(arr); |
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
| toggleComplete = itemId => { | |
| this.setState(state => { | |
| const todos = state.todos.map(todo => { | |
| return todo.id === itemId | |
| ? { ...todo, completed: !todo.completed } | |
| : todo; | |
| }); | |
| return { 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 React, { useState, useCallback } from "react"; | |
| const SearchWithHooks = () => { | |
| const [search, setSearch] = useState(""); | |
| const onSearchInputChange = useCallback(e => { | |
| setSearch(e.target.value); | |
| }, []); | |
| return ( | |
| <input |
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
| function getCarConfig(car) { | |
| const hasGoodRating = car.rating > 4; | |
| const description = hasGoodRating ? "good car" : "bad car"; | |
| const newPrice = hasGoodRating ? car.price + 1000 * car.rating : car.price; | |
| return { description, newPrice }; | |
| } |
NewerOlder