Skip to content

Window is not defined error #873

@rycustodio

Description

@rycustodio

Describe the bug

I've added a listener and this error is showing.

Steps to reproduce

This is my code:

const [branchBanner, setBannerIsShowing] = useState(false);

  useEffect(() => {
    const initAndFetch = async () => {
      const branch = (await import('branch-sdk')).default;
      branch.closeJourney();
      branch.init(key);
      branch.track('pageview', { experiment: 'gen-banner' });

      branch.setBranchViewData({
        data: {
          x: 'open',
          y: id,
        },
      });

      branch.addListener(JourneyEvent.didShowJourney, () => {
        setBannerIsShowing(true);
      });

    };

    if (isMobile) {
      void initAndFetch();
    }
  }, [isMobile, id]);

Expected Behavior

There should be no error

Additional Information/Context

No response

SDK version used (window.branch.sdk)

2.58.2

Environment

chrome Version 110.0.5481.100

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions