useMemo for string constants

Viewed 1104

in some code i have seen the below usage of useMemo. is this valid? i've been wondering what is advantage of this and why can't we simply use const?

const id = React.useMemo(() => "sort_id", []);
1 Answers

const gets reinstantiated on every render, whereas useMemo will hold the same reference until the component is unmounted/remounted.

Related