0

While trying to disable scrolling on the page setting style='overflow-y: auto;':

render() {
    return (
      <div style={{overflow-y: auto}}>
        <div>{this.props.title}</div>
        <div>{this.props.children}</div>
      </div>
    );
}

Webpack is giving an error:

enter image description here

What could I do here? If we can not set overflow-y for some reason, then how could we disable scrolling of a web page in React app (I am also using React-Bootstrap)

4
  • 1
    need to quote it? Or camel case? Commented Dec 28, 2017 at 2:51
  • 2
    overflowY . . . Commented Dec 28, 2017 at 2:52
  • 1
    Awesome, works fine, thank you! Commented Dec 28, 2017 at 2:59
  • Please select the answer below. (I don't get points, it's just so we know it's been answered.) Commented Dec 28, 2017 at 3:54

3 Answers 3

3

The style attributes should be in camel case according to the documentation.

So anywhere we delimit the words with hyphen (-) in normal css we should use change them to camel case when we use it inside a react style object.

For example.

overflow-y -> overflowY
overflow-x -> overflowX
background-image -> backgroundImage

We insert the styles as an object.

so the css properties will be attributes of an javascript object.

hyphen(-) is an illegal character when defining javascript object attributes or variable names. That's why it should be used in camel-Case.

Sign up to request clarification or add additional context in comments.

Comments

1

From the comments, use overflowY.

Comments

1

You cannot use <div style={{overflow-y: auto}}>

You have to convert it into camelCase like <div style={{overflowY: auto}}>

For details you can Check react official document Here https://reactjs.org/docs/dom-elements.html#style

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.