| 2 | import React from "react"; |
| 3 | |
| 4 | export function useTensorFlowModel(modelKind) { |
| 5 | const [model, setModel] = React.useState(null); |
| 6 | |
| 7 | const isMounted = React.useRef(true); |
| 8 | |
| 9 | React.useEffect(() => { |
| 10 | isMounted.current = true; |
| 11 | return () => (isMounted.current = false); |
| 12 | }, []); |
| 13 | |
| 14 | React.useEffect(() => { |
| 15 | setModel(null); |
| 16 | modelKind.load().then((model) => { |
| 17 | if (isMounted.current) { |
| 18 | setModel(model); |
| 19 | } |
| 20 | }); |
| 21 | }, [modelKind]); |
| 22 | |
| 23 | return model; |
| 24 | } |
| 25 | |
| 26 | export function useTensorFlowLoaded() { |
| 27 | const [isLoaded, setLoaded] = React.useState(false); |