前端小誌(轉型中)

一個用來記錄人老會忘記的地方

Faster Functional Component

2018年01月12日
OMG,好久沒更新了網誌了,其實有很多該記錄的都忘了...趕快來補一點文章。

今天在整理書籤裡面的網頁,點出了這篇

其實我不知道大部份人的寫作風格是不是stateless component,因為有一些人蠻強調這點,全部state寫進redux,還可以輔以recompose之,但我是沒看過這種專案。

stateless component乾淨但是沒有實作performance優化。我自己習慣就算只寫render還是寫class。

const Component = (props) => <div>This is a Stateless Component</div>

ReactDOM.render(
  <Component {...props} />
  ,
  mountNode
);

所以作者提出了直接用function,functional component!!

const Component = (props) => <div>This is a Stateless Component</div>

ReactDOM.render(
  {Component(props)}
  ,
  mountNode
);

原文說效能提升,我就不特別驗証了。

如果未來的某天,stateless component實作優化了,還請留言通知我啊(等好久啦)。


展開Disqus
分類
最近文章
友站連結
© 2019 Ernie Yang