50 |
51 |
Hello, WinBox!
52 |
53 |
54 |
55 | ```
56 |
57 | Or you can do more one step, to make a genuine 'windows manager', just like:
58 |
59 | ```tsx
60 | // ...
61 | // some code to maintain a list of necessary windows info...
62 | // ...
63 | const [windows, setWindows] = useState([]);
64 |
65 | const handleClose = (force, id) => {
66 | let state = [...windows];
67 | const index = state.findIndex(info => info.id === id);
68 | if (index === -1) return
69 | if (state[index].onclose && state[index].onclose(force)) return true;
70 | // window-specific onclose, returns true if it does not need the default close process.
71 | state.splice(index, 1);
72 | setTimeout(() => setWindows(state)); // to change winbox showing state while `onclose`, MUST wrap it within `setTimeout`
73 | };
74 |
75 | return (
76 | <>
77 | {windows.map(info => (
78 |