File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 1+ import { useState , useEffect } from 'react' ;
2+
3+ /**
4+ * Custom hook that returns person data of the given ID.
5+ *
6+ * @param {string } personID ID of the person for which to return data.
7+ * @param {PeopleAdapter } adapter Component data adapter from which to retrieve data.
8+ * @returns {Person } Data of the person
9+ */
10+ export default function usePerson ( personID , adapter ) {
11+ const [ person , setPerson ] = useState ( undefined ) ;
12+
13+ useEffect ( ( ) => {
14+ // eslint-disable-next-line no-console
15+ const onError = ( error ) => console . error ( error . message ) ;
16+ const subscription = adapter . getPerson ( personID ) . subscribe ( setPerson , onError ) ;
17+
18+ return ( ) => {
19+ subscription . unsubscribe ( ) ;
20+ } ;
21+ } , [ person ] ) ;
22+
23+ return person ;
24+ }
You can’t perform that action at this time.
0 commit comments