Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React.PropTypes.string deprecated #22

Open
cakeant opened this issue Nov 7, 2018 · 0 comments
Open

React.PropTypes.string deprecated #22

cakeant opened this issue Nov 7, 2018 · 0 comments

Comments

@cakeant
Copy link

cakeant commented Nov 7, 2018

Hi shiningjason,
感謝你的教學, 很清楚明瞭,
我在學習過程中發現一點問題, 回報一下希望能幫助到你更版

“Level 7. 培養好習慣,設計防呆的 React 元件”章節有用到React.PropTypes.string
但React v15.5後已經不支援React.PropTypes, 進行到這段會報錯
(教學中提供的react cdn連結 https://cdnjs.com/libraries/react 目前已經是v16)

// 1. 使用 propTypes 定義參數的型別
TodoHeader.propTypes = {
  title: React.PropTypes.string,      //Error: Cannot read property 'string' of undefined
  username: React.PropTypes.string,
  todoCount: React.PropTypes.number
};

我上網爬了一下, 目前須改用prop-types
https://reactjs.org/docs/typechecking-with-proptypes.html
index.html: include prop-types

...
<script src="https://cdnjs.cloudflare.com/ajax/libs/prop-types/15.6.0/prop-types.min.js"></script>
...

TodoHeader.js: React.PropTypes改成PropTypes

// 1. 使用 propTypes 定義參數的型別
TodoHeader.propTypes = {
  title: PropTypes.string,
  username: PropTypes.string,
  todoCount: PropTypes.number
};```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant