phanpy/src/components/AsyncText.jsx
2023-02-16 17:52:16 +08:00

12 lines
308 B
JavaScript

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;