-
-
Save designdevy/a1e95fa98a7cfc60025a4307d3838abf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const firestore = new Firestore(); | |
interface Person extends Entity { | |
name: string; | |
hairColor: string; | |
} | |
export const PersonComponent = ({ personId }: Record<"personId", string>) => { | |
const name = useSelector<any, any>(state => state.people[personId].name); | |
const hairColor = useSelector<any, any>( | |
state => state.people[personId].hairColor | |
); | |
const dispatch = useDispatch(); | |
useDoc<Person>( | |
() => firestore.doc(personId), | |
{ | |
subscribe: () => dispatch({ type: "person/subscribe", personId }), | |
unsubscribe: () => dispatch({ type: "person/unsubscribe", personId }), | |
data: person => dispatch({ type: "person/data", person }), | |
error: error => dispatch({ type: "person/error", error }) | |
}, | |
[personId] | |
); | |
return ( | |
<div> | |
<h1>Name: {name}</h1> | |
<h3>Hair Color: {hairColor}</h3> | |
</div> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment