-
-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert Wikimedia classes to components #3407
base: master
Are you sure you want to change the base?
Conversation
05ccb8f
to
bc9ffbf
Compare
This turns the WikipediaExtract file (and the mostly deprecated CommonsImage one) from classes to React components, and moves from jQuery to useCallback/useEffect hooks.
bc9ffbf
to
7c31f89
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally and works great, but could use a small cleanup.
const loadCallback: CommonsImageRequestCallbackT = | ||
React.useCallback((data) => { | ||
setCommonsImage(data); | ||
}, [setCommonsImage]); | ||
|
||
React.useEffect(() => { | ||
if (cachedImage == null) { | ||
loadCommonsImage(entity, loadCallback); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The set
function returned from useState
is stable, so there's actually no need to wrap it in useCallback
. You don't even have to include it in useEffect
dependency lists.
const loadCallback: CommonsImageRequestCallbackT = | |
React.useCallback((data) => { | |
setCommonsImage(data); | |
}, [setCommonsImage]); | |
React.useEffect(() => { | |
if (cachedImage == null) { | |
loadCommonsImage(entity, loadCallback); | |
React.useEffect(() => { | |
if (cachedImage == null) { | |
loadCommonsImage(entity, setCommonsImage); |
</div> | ||
) : null; | ||
} | ||
}, [entity, loadCallback]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}, [entity, loadCallback]); | |
}, [entity]); |
const loadCallback: WikipediaExtractRequestCallbackT = | ||
React.useCallback((data) => { | ||
setWikipediaExtract(data); | ||
}, [setWikipediaExtract]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const loadCallback: WikipediaExtractRequestCallbackT = | |
React.useCallback((data) => { | |
setWikipediaExtract(data); | |
}, [setWikipediaExtract]); |
}); | ||
React.useEffect(() => { | ||
if (cachedWikipediaExtract == null) { | ||
loadWikipediaExtract(entity, loadCallback); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loadWikipediaExtract(entity, loadCallback); | |
loadWikipediaExtract(entity, setWikipediaExtract); |
} | ||
} | ||
}, [entity, loadCallback]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}, [entity, loadCallback]); | |
}, [entity]); |
Description
This turns the
WikipediaExtract
file (and the mostly deprecatedCommonsImage
one) from classes to React components, and moves from jQuery touseCallback
/useEffect
hooks.Testing
Manually, by loading some files with both in a dev setup, such as
/artist/ae0b2424-d4c5-4c54-82ac-fe3be5453270