Skip to content

Instantly share code, notes, and snippets.

@ljmotta
Last active February 10, 2021 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ljmotta/71666f46e217ceba0c19e8dfa4eea23a to your computer and use it in GitHub Desktop.
Save ljmotta/71666f46e217ceba0c19e8dfa4eea23a to your computer and use it in GitHub Desktop.
export function useEmbeddedRef() {
const [embedded, setEmbedded] = useState<EmbeddedRef | undefined>(null);
const embeddedRef = useCallback((node: EmbeddedRef) => {
if (node !== null) {
setEmbedded(node);
}
}, []);
return { embedded, embeddedRef };
}
/// usage
const UserTaskInstanceDetailsPage: React.FC<RouteComponentProps<MatchProps> &
OUIAProps> = ({ ouiaId, ouiaSafe, ...props }) => {
// ....
// change the useRef for this, or use the hook
const [embedded, setEmbedded] = useState<TaskDetailsApi | undefined>(null);
const embeddedRef = useCallback((node: TaskDetailsApi) => {
if (node !== null) {
setEmbedded(node);
}
}, []);
// access the methods on the `embedded` variable
// ....
<EmbeddedTaskDetails
ref={embeddedRef}
targetOrigin={window.location.origin}
envelopePath={'/envelope/task-details.html'}
task={userTask}
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment