Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6214

Can I tell useMemo to skip null values in its dependency array?

$
0
0

I have a useMemo hook that wraps a component that only needs to re-render when its prop has certain shape (must not be null and must include a timestamp property).

In the below example my layout prop may have different values like null, {timestamp:1, ...}, again null...etc.

My aim is to utilize useMemo for allowing my component only re-render if layout has timestamp, otherwise it must return the memoized one.

import React, { useMemo } from "react";export default ({layout}) => {  const {timestamp} = layout || {};  return useMemo(() => <div>current state: {timestamp}</div>, [timestamp]);}

Viewing all articles
Browse latest Browse all 6214

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>