Open
Conversation
clonn
reviewed
Jun 3, 2019
Owner
clonn
left a comment
There was a problem hiding this comment.
結構上可以再多思考一下,讓整體程式碼更容易閱讀。
目前的程式是可以執行的狀態,但可以多思考一下,如何讓接手的人,程式碼更短,更好閱讀
src/components/Product.js
Outdated
| <span className="prod-info"><img width="120" src={prod.Poster} alt={prod.imdbID} /><span><a href={prod.imdbID} >{prod.Title}</a></span><span>({prod.Year})</span><span>({prod.Type})</span></span> | ||
| </li> | ||
| ); | ||
| })} |
Owner
There was a problem hiding this comment.
這部分會建議將 map 的部分拉出來一個 function 執行,
或者是切另外一個 component.
這樣再追程式碼的時候,會比較簡短,
renderProdInfo (prods) {
// put code here
}
// ...
<ul>
{ this.renderProdInfo(prods) }
</ul>
| return ( | ||
| <div id="item" key={todo.id}> | ||
| <input type='checkbox' value={todo.id} checked={todo.completed}></input>{todo.id}. {todo.title} | ||
| </div> |
Owner
There was a problem hiding this comment.
可以試試看再加上 onChange 事件,當資料改變的時候,進行 todos 資料調整。
src/components/Product.js
Outdated
| async componentDidMount() { | ||
| const prodInfo = await api.reloadOmdbDatas(); | ||
| const prods = Object.values(prodInfo)[0]; | ||
| const totalNum = Object.values(prodInfo)[1]; |
Owner
There was a problem hiding this comment.
這邊處理的時候,需要注意,需要多判斷 prodInfo 是否存在,且 prodInfo.length 有沒有,
不然 prodinfo 如果是空的,Object.values(prodInfo)[1] 就會直接炸掉
src/components/Product.js
Outdated
| return ( | ||
| <li key={index} className={prodCss}> | ||
| <span className="prod-info"><img width="120" src={prod.Poster} alt={prod.imdbID} /><span><a href={prod.imdbID} >{prod.Title}</a></span><span>({prod.Year})</span><span>({prod.Type})</span></span> | ||
| </li> |
Owner
There was a problem hiding this comment.
如果只是要做到 css 的處理,其實可以用以下這樣方式即可,判斷單數或者雙數
prod-line:nth-of-type(odd) {
background-color: #0f0;
}
Author
|
1.todos增加onChange |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
繳作業囉~
再麻煩凱薩哥哥review~
thx