相关疑难解决方法(0)

React eslint 错误?组件定义缺少显示名称

使用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)

typescript reactjs eslint

2
推荐指数
1
解决办法
6216
查看次数

标签 统计

eslint ×1

reactjs ×1

typescript ×1