Skip to content

Instantly share code, notes, and snippets.

const arr = [ ['key', 'value'], ['x', 500] ];
const obj = Object.fromEntries(arr);
toggleComplete = itemId => {
this.setState(state => {
const todos = state.todos.map(todo => {
return todo.id === itemId
? { ...todo, completed: !todo.completed }
: todo;
});
return { todos };
});
import React, { useState, useCallback } from "react";
const SearchWithHooks = () => {
const [search, setSearch] = useState("");
const onSearchInputChange = useCallback(e => {
setSearch(e.target.value);
}, []);
return (
<input
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 };
}