Last active
May 31, 2020 12:29
-
-
Save jmaicaaan/ba63150f1341f4524e25fd4c075b7def to your computer and use it in GitHub Desktop.
[DEMO - Answered] Transformers For ReactJs
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 { todoResponseToTodoListTransformer } from './todoResponseToTodoList'; | |
export const App = () => { | |
const [todos, setTodos] = useState([]); | |
useEffect(() => { | |
const getTodos = async () => { | |
const { data } = await axios.get('https://jsonplaceholder.typicode.com/todos/'); | |
const transformedTodos = data.map(todoResponseToTodoListTransformer); // ✅ | |
setTodos(transformedTodos); | |
}; | |
getTodos(); | |
}, []); | |
return ( | |
<div> | |
<TodoList | |
todos={todos} | |
/> | |
</div> | |
); | |
}; | |
const TodoList = ({ | |
todos | |
}) => ( | |
<div> | |
<h1>Todo List</h1> | |
<ul> | |
{todos.map((todo) => ( | |
<li | |
key={todo.id} | |
style={{ | |
textDecoration: todo.isCompleted ? 'line-through' : 'none' | |
}} | |
> | |
{todo.title} | |
</li> | |
))} | |
</ul> | |
</div> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment