Created
October 14, 2020 13:53
-
-
Save ljmotta/6ac056652a4bb5ce135c05143925d8d7 to your computer and use it in GitHub Desktop.
TodoListEnvelopeView Use Imperative Handle
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
import { useImperativeHandle } from "react"; | |
export const TodoListEnvelopeView = React.forwardRef<TodoListEnvelopeViewApi, Props>((props, forwardedRef) => { | |
// ... | |
useImperativeHandle( | |
forwardedRef, | |
() => ({ | |
setUser, | |
addItem: (item) => setItems([...items, { label: item, completed: false }]), | |
getItems: () => items, | |
markAllAsCompleted: () => setItems(items.map((item) => ({ ...item, completed: true }))), | |
}), | |
[items] | |
); | |
// ... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment