π νν 리μΌμ λ°λΌν νλ‘μ νΈμ λλ€!
app.js νμΌμμ onRemove
ν¨μλ₯Ό μμ±ν©μλ€.
const onRemove = id => e => {
setTodos(todos.filter(todo => todo.id !== id));
};
μ΄ ν¨μμμλ setTodosλ₯Ό μ¬μ©νμ¬ μνλ₯Ό μ λ°μ΄νΈ ν΄μ€λλ€. κ° μμ΄ν μ κ³ μ idλ₯Ό λ°μμμ ν΄λΉ μμ΄λλ₯Ό κ°μ§ μμ΄ν κ°μ²΄λ§ μ μΈνκ³ μλ‘μ΄ λ°°μ΄μ λ§λλ ν¨μ μ λλ€.
<TodoList todos={todos} onRemove={onRemove} />
const TodoList = ({todos, onRemove}) => {
return (
<ScrollView contentContainerStyle={styles.listContainer}>
{todos.map(todo => (
<TodoListItem key={todo.id} {...todo} onRemove={onRemove} />
))}
</ScrollView>
);
};
const TodoListItem = ({textValue, id, checked, onRemove}) => {
return (
<View style={styles.container}>
...
<TouchableOpacity style={styles.buttonContainer}>
<Text style={styles.buttonText} onPress={onRemove(id)}>
<Icon name="delete" size={30} color="#e33057" />
</Text>
</TouchableOpacity>
</View>
);
};