使用Reac.memo包裹我的功能组件,它可以流畅运行,但eslint总是让我想起了两个错误:
error Component definition is missing display name react/display-name
error 'time' is missing in props validation react/prop-types
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
type Data = {
time: number;
};
const Child: React.FC<Data> = React.memo(({ time }) => {
console.log('child render...');
const newTime: string = useMemo(() => {
return changeTime(time);
}, [time]);
return (
<>
<p>Time is {newTime}</p>
{/* <p>Random is: {children}</p> */}
</>
);
});
Run Code Online (Sandbox Code Playgroud)
我的整个代码:
import React, { useState, useMemo } from 'react';
const Father = () => {
const [time, …Run Code Online (Sandbox Code Playgroud)