小编paz*_*zta的帖子

我可以在React Hooks中使用箭头功能代替常规功能吗?

是否还可以将箭头函数与新的React Hook语法一起使用?有什么区别和/或可能引起问题?

文档语法:

function Example() {

  const [count, setCount] = useState(0);

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}
Run Code Online (Sandbox Code Playgroud)

箭头功能:

 const Example = () => {

  const [count, setCount] = useState(0);

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}
Run Code Online (Sandbox Code Playgroud)

reactjs react-hooks

9
推荐指数
2
解决办法
2199
查看次数

时刻unix时间戳格式错误的日期

我想将 Unix 毫秒时间戳转换为可读日期。

我的时间戳是 1525772511140。正确的输出应该类似于:29-05-2018 9:41:51AM

现在我的代码返回错误的日期:31-10-50319 03:10...

代码:

var timeStamp = new Date(1525772511140 * 1000);
var date = moment(timeStamp).format('DD-MM-YYYY HH:mm');
console.log(date);
Run Code Online (Sandbox Code Playgroud)

javascript momentjs

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

javascript ×1

momentjs ×1

react-hooks ×1

reactjs ×1