react-phone-input icon indicating copy to clipboard operation
react-phone-input copied to clipboard

Doesn't work with Server Rendering

Open mienaikoe opened this issue 9 years ago • 4 comments

Hey there,

I use a polymorphic web server with ReactDOM.renderToString() on server-side, and ReactDOM.render() on client-side. Currently when I use react-phone-input on server-side, I get this error:

ReferenceError: document is not defined at Object.<anonymous> ([...]/node_modules/react-phone-input/dist/index.js:1:2330)

It looks like the component wasn't designed to work on the server if it requires a var provided by the browser. would love to use this on the server too so it fits with polymorphism.

I'm using version 1.1.3 of react-phone-input

mienaikoe avatar Sep 27 '16 15:09 mienaikoe

@mienaikoe Yes you are right, we currently haven't modified/updated it to work with server rendering sadly.

sample-usr avatar Sep 28 '16 14:09 sample-usr

@razagill Do you guys have any plan to update it for ssr?

HiradRoshandel avatar May 10 '17 14:05 HiradRoshandel

@aconital not at the moment.

sample-usr avatar May 10 '17 14:05 sample-usr

I come up with the following workaround solution. I used NoSSR package to conditionally load React Phone Input:

<NoSSR>
    {this.renderPhone()}
</NoSSR>

And then in renderPhone method:

  renderPhone = () => {
      let ReactPhoneInput = require('react-phone-input').default

      return (
       <ReactPhoneInput
          value={...}
          defaultCountry={...}
          onChange={...} />
      )
  }

However, this seems to be a bicycle. +1 to this requested feature.

piupiupiu avatar Nov 20 '17 17:11 piupiupiu