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
RedirectComponent: refactor to function component #558
RedirectComponent: refactor to function component #558
Conversation
👷 Deploy request for scrivito-example accepted.
|
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.
FEEDBACK (d26d91c)
Nice start 🚀! Please see my comments.
|
||
render() { | ||
const link = this.props.page.get("link"); | ||
}, [page]); |
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.
I think it would be better to first const link = page.get("link");
and add link
to the dependency of useEffect
.
Something like:
const link = page.get("link");
React.useEffect(() => {
if (!link) return;
Scrivito.load(() => Scrivito.urlFor(link)).then((url) => {
if (link.isExternal()) {
window.top.location.replace(url);
} else {
window.location.replace(url);
}
}
}, [link]);
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.
FEEDBACK (b173bc9)
Nice progress. See my comments for further improvements.
const url = link && Scrivito.urlFor(link); | ||
Scrivito.provideComponent("Redirect", ({ page }) => { | ||
const link = page.get("link"); | ||
const url = link && Scrivito.urlFor(link); |
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.
Please move the url resolving with a load
inside of the useEffect
. Otherwise its possible that the useEffect
is triggered twice - first with the "unresolved" urlFor(link)
and then with the resolved/loaded urlFor(link)
.
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.
LGTM (a4cf776)
Nice 🚀!
No description provided.