Giter VIP home page Giter VIP logo

react-render-props's Introduction

React-Render-Props

Rendering props in React

The main difference between state and props is that props are immutable. The container component should define the state that can be updated and changed, while the child components should only pass data from the state using props.

You'll need immutable data in your component, so you can just add props to reactDOM.render() function in main.js and use it inside the main component.

In this example we set a default property values directly on the component constructor instead of adding it to the reactDom.render() element.

We are using a class based component in this example, class based components are easier to maintain the state of app, they can also have lifecycle methods.

We combined the state and props in the app. We are setting the state in our parent component and passing it down the component tree using props. Inside the render function, we are setting headerProp and contentProp used in child components. Hence the term passing props.

Some of the lifecycle methods have been deprecated, here is an example (see next line)

class App extends Component {

UNSAFE_componentWillMount() {

}

}

This is a nudge to get all React developers to stop using these methods. (You must not use it)

To allow easy renaming for projects where we may not have adequate time to migrate to the recommended lifecycle methods, the React team recommended a script from codemod that automates this process. (See next line)

cd your_project

npx react-codemod rename-unsafe-lifecycles

This will rename all the affected lifecycle methods to prepare for the migration to React 17.

react-render-props's People

Contributors

upperlefty avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.