todo.completed = !todo.completed
if (todo.id === id) return { ...todo, completed: !todo.completed }
return todo
onChange={() => props.handleChange(props.item.id, !props.item.completed)}
handleChange(id, newCompleted) {
this.setState(prevState => {
const updatedTodos = prevState.todos.map(todo => {
if (todo.id === id) {
todo.completed = newCompleted
}
return todo
})
return {
todos: updatedTodos
}
})
export default function Method({title, description, name, isActive}) {
...
<Button
name={name}
className={style.button + (isActive ? ' active-class' : '')}
export default function Method({title, description, name, activeName}) {
const isActive = name === ActiveName
...
<Button
name={name}
className={style.button + (isActive ? ' active-class' : '')}
{
items: [],
settings: {
key1: { filter: {}, sort: {}, page: 2 },
key2: { filter: {}, sort: {}, page: 1 },
}
}
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.myRef = React.createRef();
}
render() {
return <div className={"someClass"} ref={this.myRef} />;
}
}
const index = state.tasksData.findIndex(({ ID }) => ID === payload.ID)
if (index > -1) return {
...state,
tasksData:
state.tasksData.slice(0, index).concat(
state.tasksData.slice(index + 1))
}
const App = () => {
const [showComponent, changeShowComponent] = useState(0)
return <div>
<button onClick={() => changeShowComponent(1)}>Начинаем</button>
{showComponent === 1 && <FirstModalComponent changeShowComponent />}
{showComponent === 2 && <SecondModalComponent changeShowComponent />}
</div>
}
changeShowComponent(2)
и все перерисуется, первый компонент исчезнет, второй появится