ant-design/.dumi/hooks/use.ts
MadCcc bed26741aa
docs: polyfill React.use (#43755)
* docs: polyfill React.use

* chore: code clean

* chore: code clean

* docs: add banner fallback

* chore: code clean
2023-07-24 16:59:35 +08:00

24 lines
534 B
TypeScript

export default function use(promise: any) {
if (promise.status === 'fulfilled') {
return promise.value;
}
if (promise.status === 'rejected') {
throw promise.reason;
} else if (promise.status === 'pending') {
throw promise;
} else {
promise.status = 'pending';
promise.then(
(result) => {
promise.status = 'fulfilled';
promise.value = result;
},
(reason) => {
promise.status = 'rejected';
promise.reason = reason;
},
);
throw promise;
}
}