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

isomorphic apps #5

Open
Bamieh opened this issue Dec 15, 2016 · 6 comments
Open

isomorphic apps #5

Bamieh opened this issue Dec 15, 2016 · 6 comments

Comments

@Bamieh
Copy link

Bamieh commented Dec 15, 2016

Hello
I havent tried your component yet, but i am getting this error already because my application runs on both the server and client.

ReferenceError: window is not defined\n at node_modules/react-parallax-component/dist/index.min.js:19:2129\

@keske
Copy link
Owner

keske commented Dec 16, 2016

Hi Bamieh, thank you, I'll check it!

@MadeInMoon
Copy link

I had a the same problem with the lib headroom.js. I had to do the following in my component:

const Headroom = process.env.BROWSER ? require('headroom.js') : '';


class Header extends React.Component {
  componentDidMount() {
      if (process.env.BROWSER) {
         // use here
      }
  }

  render() {...}
}

@Bamieh
Copy link
Author

Bamieh commented Jan 17, 2017

@MadeInMoon yes, true this can be done like such with require, not import. thanks. btw, componentDidMount only runs on the browser.

@MadeInMoon
Copy link

@Bamieh thanks ;)

@yayromina
Copy link

Any update on supporting isomorphic apps?

@MadeInMoon
Copy link

@yayromina, it is actually usable. See the code below.

note: I added the prop scrollContainer, which allows to listen the scroll of a specific container. You could pass window.

1 - Make your own <ParallaxComponent /> component

Take the source component and copy it into a new component in your project

  • Add scrollContainer in PropTypes
static propTypes = {
  ...
  scrollContainer: React.PropTypes.object,
  ...
}
  • Replace all window variables by this.props.scrollContainer

2 - In your component calling <ParallaxComponent />

  • import you own component

import ParallaxComponent from '../../myComponents/ParallaxComponent';

  • componentDidMount
componentDidMount() {
  this.setState({ isMounted: true });
}
  • render
{this.state.isMounted?
  <ParallaxComponent
    speed={0.05}
    top="60%"
    scrollContainer={this.refs.container}>
    <p>Winter is coming</p>
  </Parallax>
:
 ''
}

Not an ideal solution, but sounds good to you?

Anyone did better/simpler with a custom scroll container?

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

No branches or pull requests

3 participants