Skip to content

React homework - 嘉義 Amo Lin#4

Open
amo-lin wants to merge 3 commits intoclonn:masterfrom
amo-lin:master
Open

React homework - 嘉義 Amo Lin#4
amo-lin wants to merge 3 commits intoclonn:masterfrom
amo-lin:master

Conversation

@amo-lin
Copy link

@amo-lin amo-lin commented Jun 3, 2019

繳作業囉~
再麻煩凱薩哥哥review~

thx

Copy link
Owner

@clonn clonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

結構上可以再多思考一下,讓整體程式碼更容易閱讀。

目前的程式是可以執行的狀態,但可以多思考一下,如何讓接手的人,程式碼更短,更好閱讀

<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>
);
})}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這部分會建議將 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>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以試試看再加上 onChange 事件,當資料改變的時候,進行 todos 資料調整。

async componentDidMount() {
const prodInfo = await api.reloadOmdbDatas();
const prods = Object.values(prodInfo)[0];
const totalNum = Object.values(prodInfo)[1];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這邊處理的時候,需要注意,需要多判斷 prodInfo 是否存在,且 prodInfo.length 有沒有,
不然 prodinfo 如果是空的,Object.values(prodInfo)[1] 就會直接炸掉

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>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果只是要做到 css 的處理,其實可以用以下這樣方式即可,判斷單數或者雙數

prod-line:nth-of-type(odd) {
  background-color: #0f0;
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這語法好方便啊! @@

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

welcome to CSS.

@amo-lin
Copy link
Author

amo-lin commented Jun 5, 2019

1.todos增加onChange
2.針對凱薩哥哥提出的建議進行修正

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

Successfully merging this pull request may close these issues.

2 participants