Skip to content
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

Doesn't work with Server Rendering #30

Open
mienaikoe opened this issue Sep 27, 2016 · 4 comments
Open

Doesn't work with Server Rendering #30

mienaikoe opened this issue Sep 27, 2016 · 4 comments

Comments

@mienaikoe
Copy link

mienaikoe commented Sep 27, 2016

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

@sample-usr
Copy link
Owner

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

@aconital
Copy link

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

@sample-usr
Copy link
Owner

@aconital not at the moment.

@piupiupiu
Copy link

piupiupiu commented Nov 20, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants