皆さんこんにちは。先日公開した以下の記事は多くの方にご覧いただきありがとうございます。 この記事に対して多く見られた反響のひとつは、コンポーネント内に use(fetchNote(id)) という非同期処理を行うコードが含まれていることに対する違和感です。 function Note({id, shouldIncludeAuthor}) { // ↓↓↓↓↓ const note = use(fetchNote(id)); let byline = null; if (shouldIncludeAuthor) { const author = use(fetchNoteAuthor(note.authorId)); byline = <h2>{author.displayName}</h2>; } return ( <div> <h1>{note.title}</h1> {byline}
![なんでコンポーネントに副作用があんだよ! 教えはどうなってんだ教えは!](https://cdn-ak-scissors.b.st-hatena.com/image/square/395d31c8a9d52bd8dad9ba0dae2f70e998dd0ae5/height=288;version=1;width=512/https%3A%2F%2Fres.cloudinary.com%2Fzenn%2Fimage%2Fupload%2Fs--G-5cDlUE--%2Fc_fit%252Cg_north_west%252Cl_text%3Anotosansjp-medium.otf_55%3A%2525E3%252581%2525AA%2525E3%252582%252593%2525E3%252581%2525A7%2525E3%252582%2525B3%2525E3%252583%2525B3%2525E3%252583%25259D%2525E3%252583%2525BC%2525E3%252583%25258D%2525E3%252583%2525B3%2525E3%252583%252588%2525E3%252581%2525AB%2525E5%252589%2525AF%2525E4%2525BD%25259C%2525E7%252594%2525A8%2525E3%252581%25258C%2525E3%252581%252582%2525E3%252582%252593%2525E3%252581%2525A0%2525E3%252582%252588%2525EF%2525BC%252581%2525E3%252580%252580%2525E6%252595%252599%2525E3%252581%252588%2525E3%252581%2525AF%2525E3%252581%2525A9%2525E3%252581%252586%2525E3%252581%2525AA%2525E3%252581%2525A3%2525E3%252581%2525A6%2525E3%252582%252593%2525E3%252581%2525A0%2525E6%252595%252599%2525E3%252581%252588%2525E3%252581%2525AF%2525EF%2525BC%252581%252Cw_1010%252Cx_90%252Cy_100%2Fg_south_west%252Cl_text%3Anotosansjp-medium.otf_37%3Auhyo%252Cx_203%252Cy_121%2Fg_south_west%252Ch_90%252Cl_fetch%3AaHR0cHM6Ly9zdG9yYWdlLmdvb2dsZWFwaXMuY29tL3plbm4tdXNlci11cGxvYWQvYXZhdGFyLzVjYjFlMDJlNGQuanBlZw%3D%3D%252Cr_max%252Cw_90%252Cx_87%252Cy_95%2Fv1627283836%2Fdefault%2Fog-base-w1200-v2.png)