0

I want to know the proper method to use render(){} while I'm using the functional component.

i'm new on reactjs, so far i'm always using functional component on everything :

const Something = () => {
}
export default Something

What i want is to render object which is react-scroll-parallax, while i'm using functional component, but i don't know the proper method to do that :

const Something = () => {
    render() {
      return (
         <ParallaxProvider>
           <Parallax className="custom-class" y={[-20, 20]} tagOuter="figure">
             <ImageBg src="../../images/wpbatik.jpg" />
           </Parallax>
         </ParallaxProvider>
      );
    }
}
export default Something

Thank you

3
  • 1
    In functional components there is no render, just return whatever you want rendered from the function. Commented Jan 3, 2022 at 15:09
  • 1
    I'd highly recommend reading up more on how functional components work, e.g. twilio.com/blog/react-choose-functional-components. There are going to be many further differences which will require your attention, such as the component lifecycle. Commented Jan 3, 2022 at 15:12
  • 1
    This is literally the first code sample in the React.js docs under 'Components' - reactjs.org/docs/… Commented Jan 3, 2022 at 15:12

1 Answer 1

1

In a functional component, you use return and it will work the same way as return inside of the render() {} function in a class-based component.

Example:

function App() {
  return(
    <div>Some stuff inside</div>
  )
}

Here's a class based version of it:

class App extends React.Component {
  render() {
    return <div>Some stuff inside</div>;
  }
}
Sign up to request clarification or add additional context in comments.

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.