Coder Social home page Coder Social logo

m-zubairahmed / passing-data-in-react Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 102 KB

A demo app to understand data transfer between components in react

Home Page: https://dataflow-in-react.herokuapp.com/

HTML 14.13% JavaScript 85.87%
reactjs demo-app

passing-data-in-react's Introduction

Passing-Data-in-React

A demo app to understand flow of data in react.

Introduction

React has one way of data flow, but sometimes it needs to be able to move from child to parent, parent to child or among children components.

Program structure

  • Index
    • ProductList
      • InputBrand
      • Product
      • Total

Types of flow

Parent to Child

If parent have data then it can pass it down to its children via props.

[photo here]

and in the child, those passed props can be accessed by

this.props.passedDownIdentifier

Props are immutable in child components.

Child to Parent

If child have data which parent needs to have access to then it is done via callback

  1. Constuct the method in the parent with the parameters which you will recieve from the child.
callbackMethodInParent = (dataFromChild) => {
  // foo bar
};
  1. Pass the constructed callback method to the child as props.
<ChildComponent callbackMethodInParent = {this.callbackMethodInParent} />
  1. In the child call the callback with the data you recieved.
this.props.callbackMethodInParent(newData);

[combined image with number tags]

Page status

https://updown.io/suC9

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.