cinny/src/app/hooks/useSelectedSpace.js
Ajay Bura 992da7c7be Refactor navigation
Signed-off-by: Ajay Bura <ajbura@gmail.com>
2022-01-26 17:03:26 +05:30

21 lines
623 B
JavaScript

/* eslint-disable import/prefer-default-export */
import { useState, useEffect } from 'react';
import cons from '../../client/state/cons';
import navigation from '../../client/state/navigation';
export function useSelectedSpace() {
const [spaceId, setSpaceId] = useState(navigation.selectedSpaceId);
useEffect(() => {
const onSpaceSelected = (roomId) => {
setSpaceId(roomId);
};
navigation.on(cons.events.navigation.SPACE_SELECTED, onSpaceSelected);
return () => {
navigation.removeListener(cons.events.navigation.SPACE_SELECTED, onSpaceSelected);
};
}, []);
return [spaceId];
}