Windy Community
    • Unread
    • Categories
    • Groups
    • Go to windy.com
    • Register
    • Login

    Has anybody used windy api with ReactJS or NextJs. Is it possible?

    Scheduled Pinned Locked Moved Windy API v4
    7 Posts 3 Posters 2.1k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Madusara LiyanageM Offline
      Madusara Liyanage
      last edited by

      I created a nextjs component like this. Sometimes it works, but most of the time I see only a grey outlined map with no data and I get the error "ReferenceError: window is not defined" in the console.

      1c025395-9872-4ce9-8053-5648e1225fd4-image.png

      result

      2a2022fc-ea47-44ef-bb91-abad13347c05-image.png

      David Ryzec 3D 1 Reply Last reply Reply Quote 0
      • jorgefJ Offline
        jorgef External Developers | Premium
        last edited by

        Hello, I don't use NextJS but this error looks like you're trying to access browser-only symbols on the server. You need to first check if the environment is browser.

        Madusara LiyanageM 2 Replies Last reply Reply Quote 1
        • David Ryzec 3D Offline
          David Ryzec 3 Windy Staff @Madusara Liyanage
          last edited by

          @Madusara-Liyanage Hi, make sure your code only runs in browser and not on server.

          Madusara LiyanageM 2 Replies Last reply Reply Quote 1
          • Madusara LiyanageM Offline
            Madusara Liyanage @jorgef
            last edited by

            @jorgef said in Has anybody used windy api with ReactJS or NextJs. Is it possible?:

            Hello, I don't use NextJS but this error looks like you're trying to access browser-only symbols on the server. You need to first check if the environment is browser.

            Thank you for your response.
            I added a window check condition inside the useEffect. But still the same behaviour is observed.

            useEffect(() => {
                if (typeof window !== 'undefined') {
                  // rest of the code
                }
            }, [])
            

            When I do a change in the code (say add some styles to the div and save) the map is displayed properly for just one time. On subsequent page refreshes, the map is grey with the initial error message in the console. But in some random page refreshes, map is properly displayed.

            1 Reply Last reply Reply Quote 0
            • Madusara LiyanageM Offline
              Madusara Liyanage @jorgef
              last edited by

              @jorgef said in Has anybody used windy api with ReactJS or NextJs. Is it possible?:

              Hello, I don't use NextJS but this error looks like you're trying to access browser-only symbols on the server. You need to first check if the environment is browser.

              Thank you for your response.
              I added a window check condition inside the useEffect. But still the same behaviour is observed.

              useEffect(() => {
                  if (typeof window !== 'undefined') {
                    // rest of the code
                  }
              }, [])
              

              When I do a change in the code (say add some styles to the div and save) the map is displayed properly for just one time. On subsequent page refreshes, the map is grey with the initial error message in the console. But in some random page refreshes, map is properly displayed.

              1 Reply Last reply Reply Quote 0
              • Madusara LiyanageM Offline
                Madusara Liyanage @David Ryzec 3
                last edited by

                @David-Ryzec-3

                Thank you so much for your response. I added a condition - if (typeof window !== 'undefined') inside the useEffect

                useEffect(() => {
                    if (typeof window !== 'undefined'){
                        // rest of the code
                    }
                }, [])
                

                But still getting the same error.

                1 Reply Last reply Reply Quote 0
                • Madusara LiyanageM Offline
                  Madusara Liyanage @David Ryzec 3
                  last edited by

                  @David-Ryzec-3

                  Thank you so much for your response. I added a condition - if (typeof window !== 'undefined') inside the useEffect

                  useEffect(() => {
                      if (typeof window !== 'undefined'){
                          // rest of the code
                      }
                  }, [])
                  

                  But still getting the same error.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Windy Community  |  Powered by excellent NodeBB
                  Terms of Use     Privacy Policy     Windy.com