mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-03 00:09:39 +08:00
bed26741aa
* docs: polyfill React.use * chore: code clean * chore: code clean * docs: add banner fallback * chore: code clean
24 lines
534 B
TypeScript
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;
|
|
}
|
|
}
|