Conversation
sor4chi
requested changes
Nov 9, 2023
| function App() { | ||
| const [posts, setPosts] = useState([]); | ||
| const [isLoading, setIsLoading] = useState(false); | ||
| const [LoadFailed, setLoadFailed] = useState(false); |
Member
There was a problem hiding this comment.
細かい指摘になってしまいますが、JavaScriptでは変数や関数の命名はlowerCamelCaseで行うような慣習があります。
また、Booleanの変数にはprefixにisやcanなどをつけるような慣習があります。変数を見た時に大体どういうことを想定した変数なのかを判断するために命名を規則づけているんです。
今回だとisLoadFailed / setIsLoadFailedのような命名にするのが良いと思います!
Comment on lines
+36
to
+41
| <Typography textAlign="center" | ||
| variant="h6" | ||
| sx={{ color: 'error.main' }} | ||
| > | ||
| {LoadFailed ? "読み込みに失敗しました": ""} | ||
| </Typography> |
Member
There was a problem hiding this comment.
この表示はいいと思います、確かに失敗した時にエラーメッセージ出るのはいいですよね。
ただ、LoadFailedがfalseの時にから文字列が返されることから、エラーでない場合は空の<Typography>が存在してしまうことになります。
なのでTypography全体を出し分けるようにすると良いと思います。
Suggested change
| <Typography textAlign="center" | |
| variant="h6" | |
| sx={{ color: 'error.main' }} | |
| > | |
| {LoadFailed ? "読み込みに失敗しました": ""} | |
| </Typography> | |
| {LoadFailed && ( | |
| <Typography textAlign="center" | |
| variant="h6" | |
| sx={{ color: 'error.main' }} | |
| > | |
| 読み込みに失敗しました | |
| </Typography> | |
| )} |
Member
There was a problem hiding this comment.
- ちなみに
&&演算子は、左オペランド(今回だとLoadFailed)がtrueの時に右オペランド(今回だとTypography)を返す、falseの時はfalseを返すという挙動をします - Reactではfalseを埋め込むと存在が消されるのでうまく動くというわけです。
ここについてわからなかったら言ってください!
Member
|
??? |
Author
|
間違えて押しちゃっててしかも気づいてませんでした |
Member
|
あるある |
1 similar comment
Member
|
あるある |
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.
No description provided.