I have read about the nested component in React.
I tried with this example and noticed that each time I updated the state of the parent component (todolist). The DOM tree re-render the whole instead of add new.
My question is: Is it an anti-pattern that we should avoid?
const TodoList = ({ todos, onTodoClick }) => {
const Todo = ({ completed, text, onClick }) => {
return (
<li onClick={onClick} style={{ textDecoration: completed ? 'line-through' : 'none' }}>
{text}
</li>
);
};
return todos.map(todo => <Todo key={todo.id} {...todo} onClick={() => onTodoClick(todo.id)} />);
};