import React, { useState } from "react";
const App = () => {
/** Так */
const [user, setUser] = useState({
username: "lol",
isBanned: false,
});
/** Или отдельным, так */
const [user, setUser] = useState({
username: "lol"
});
const [isBanned, setBanned] = useState(false);
return (
<>
{/** В первом случае */}
<span>{user.isBanned ? "Забанен" : "Бана нет"}</span>
<button onClick={() => setUser({ username: "Alekosh", isBanned: false })}>
btn1
</button>
<button onClick={() => setUser({ username: "Ambrose", isBanned: true })}>
btn2
</button>
{/** Во втором случае */}
<span>{isBanned ? "Забанен" : "Бана нет"}</span>
<button onClick={() => setUser({ username: "Alekosh" })}>
btn1
</button>
<button onClick={() => setUser({ username: "Ambrose" })}>
btn2
</button>
</>
);
};
export default App;