Add categorized spaces hook
Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
parent
424245df18
commit
e63f8ab8b8
1 changed files with 25 additions and 0 deletions
25
src/app/hooks/useCategorizedSpaces.js
Normal file
25
src/app/hooks/useCategorizedSpaces.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
/* eslint-disable import/prefer-default-export */
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
import initMatrix from '../../client/initMatrix';
|
||||
import cons from '../../client/state/cons';
|
||||
|
||||
export function useCategorizedSpaces() {
|
||||
const { accountData } = initMatrix;
|
||||
const [categorizedSpaces, setCategorizedSpaces] = useState([...accountData.categorizedSpaces]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleCategorizedSpaces = () => {
|
||||
setCategorizedSpaces([...accountData.categorizedSpaces]);
|
||||
};
|
||||
accountData.on(cons.events.accountData.CATEGORIZE_SPACE_UPDATED, handleCategorizedSpaces);
|
||||
return () => {
|
||||
accountData.removeListener(
|
||||
cons.events.accountData.CATEGORIZE_SPACE_UPDATED,
|
||||
handleCategorizedSpaces,
|
||||
);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return [categorizedSpaces];
|
||||
}
|
Loading…
Reference in a new issue