https://linen.dev logo
*<back2dos>* yeah, I mean the problem is simply th...
# react
u
yeah, I mean the problem is simply that react life cycle events are not very well designed and instead of improving that, React team seems hell-bent to not use classes because FP is the solution to everything This is the proposed method:
Copy code
js
export function Layout(props) {
  const [isSidebarExpanded, setSideBarExpanded] = useState(true);

  function handleRouteChange(url) {
    setSideBarExpanded(true);
  }

  useEffect(function routeChangeComplete() {
    Router.events.on('routeChangeComplete', handleRouteChange);
    return () => Router.events.off('routeChangeComplete', handleRouteChange);
  },[]);
  // ...
Here's the same in coconut with evil, evil classes:
Copy code
haxe
class Layout extends View {
  @:state isSidebarExpanded:Bool = true;

  function handleRouteChange(url) {
    isSidebarExpanded = true;
  }

  function viewDidMount() {
    Router.events.on('routeChangeComplete', handleRouteChange);
    beforeUnmounting(() -> Router.events.off('routeChangeComplete', handleRouteChange));
  });
  // ...
This could practically look exactly the same in React, if they were to work a bit on the life cycle events