phanpy/src/components/AsyncText.jsx

13 lines
308 B
React
Raw Normal View History

2023-02-16 09:51:54 +00:00
import { useEffect, useState } from 'preact/hooks';
function AsyncText({ children }) {
if (typeof children === 'string') return children;
const [text, setText] = useState('');
useEffect(() => {
Promise.resolve(children).then(setText);
}, [children]);
return text;
}
export default AsyncText;