Merge branch 'develop' into improved-forwarding-ui
This commit is contained in:
commit
a06306d560
91 changed files with 1240 additions and 1002 deletions
|
@ -14,14 +14,22 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import {useState, useEffect, DependencyList} from 'react';
|
||||
import { useState, useEffect, DependencyList } from 'react';
|
||||
|
||||
type Fn<T> = () => Promise<T>;
|
||||
|
||||
export const useAsyncMemo = <T>(fn: Fn<T>, deps: DependencyList, initialValue?: T): T => {
|
||||
const [value, setValue] = useState<T>(initialValue);
|
||||
useEffect(() => {
|
||||
fn().then(setValue);
|
||||
let discard = false;
|
||||
fn().then(v => {
|
||||
if (!discard) {
|
||||
setValue(v);
|
||||
}
|
||||
});
|
||||
return () => {
|
||||
discard = true;
|
||||
};
|
||||
}, deps); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
return value;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue