992da7c7be
Signed-off-by: Ajay Bura <ajbura@gmail.com>
21 lines
623 B
JavaScript
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];
|
|
}
|