refactor: move fetch-logic to custom hook to separate responsibilities #187
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.
Why is this pull request needed?
This pull request is needed because we don't want to break SOLID principles. (Single Responsibility Principle)
What does this pull request change?
type CommitInfo
to get better documentation of the codeVersionText.tsx
, reducing the need of conditional rendering (potentially slightly better performance), making the code adaptable to changes.Ideally, I'd like the component to be even more independent of the fetch, but after I added the new error message, I noticed that the endpoint threw 404, and it'd be nice to see the what a successful response looked like. I think it makes sense to try to fix that first, and then continue the refactoring after. #188
Given that the response is expected to be successful, it could be easier to predict what
VersionText.txt
returned ifcommitInfo
was undefined initially. That way, the fetch-function would bear the whole responsibility for handling the fetch-response. We could have confidence that the only reason forcommitInfo
to appear missing in the JSX component, is that it doesn't exist, and not because it fails to handle the fetch-response (it shouldn't be responsible for that). Ternary operators checking for''
could at least be replaced by nullish coalescing operators, resulting in one less option for what the output might be. Maybe it's possible to remove conditionals altogether, depending on what a typical response look like.