Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Bugfix for populate not firing due to htmlDocument being undefined. M…
Browse files Browse the repository at this point in the history
…oved firing login in useEffect (#28)
  • Loading branch information
AugusteBa authored and oriondean committed Oct 29, 2019
1 parent b387dd1 commit 9aaa1bd
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/useNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default ({
}: IUseNotificationOptions) => {
const [name, setName] = useState<string | null>(null);
const [htmlDocument, setHtmlDocument] = useState<HTMLDocument | null>(null);
const [populateJsx, setPopulateJsx] = useState<JSX.Element | null>(null);
const [ref, setRef] = useState<IOpenFinNotification | null>(null);
const [notificationWindow, dispatch] = useReducer(
reducer,
Expand Down Expand Up @@ -91,10 +92,15 @@ export default ({
}, [ref]);

useLayoutEffect(() => {
if (jsx && notificationWindow.state === "LAUNCHED" && htmlDocument) {
populate(jsx);
const jsxElement = populateJsx ? populateJsx : jsx;
if (
jsxElement &&
notificationWindow.state === "LAUNCHED" &&
htmlDocument
) {
populate(jsxElement);
}
}, [jsx, name, notificationWindow]);
}, [jsx, populateJsx, name, notificationWindow]);

useEffect(() => {
if (shouldInheritCss) {
Expand Down Expand Up @@ -207,7 +213,8 @@ export default ({

const populate = useCallback(
(jsxElement: JSX.Element) => {
if (htmlDocument && htmlDocument) {
setPopulateJsx(jsxElement);
if (htmlDocument) {
try {
dispatchNewState(WINDOW_STATE.POPULATING);
ReactDOM.render(
Expand Down

0 comments on commit 9aaa1bd

Please sign in to comment.