score:93

Accepted answer

you would need to pass down each prop individually for each function that you needed to call

<createprofile
  onfirstnamechange={this.firstnamechange} 
  onhide={close}
  show={this.state.showmodal}
/>

and then in the createprofile component you can either do

const createprofile = ({onfirstnamechange, onhide, show }) => {...}

with destructuring it will assign the matching property names/values to the passed in variables. the names just have to match with the properties

or just do

const createprofile = (props) => {...}

and in each place call props.onhide or whatever prop you are trying to access.

score:1

a variation of finalfreq's answer

you can pass some props individually and all parent props if you really want (not recommended, but sometimes convenient)

<createprofile
  {...this.props}
  show={this.state.showmodal}
/>

and then in the createprofile component you can just do

const createprofile = (props) => { 

and destruct props individually

const {onfirstnamechange, onhide, show }=props;

score:4

just do this on source component

 <mydocument selectedquestiondata = {this.state.selectedquestionanswer} />

then do this on destination component

const mydocument = (props) => (
  console.log(props.selectedquestiondata)
);

score:6

an addition to the above answer.

if react complains about any of your passed props being undefined, then you will need to destructure those props with default values (common if passing functions, arrays or object literals) e.g.

const createprofile = ({
  // defined as a default function
  onfirstnamechange = f => f,
  onhide,
  // set default as `false` since it's the passed value
  show = false
}) => {...}

score:34

i'm using react function component
in parent component first pass the props like below shown

import react, { usestate } from 'react';
import './app.css';
import todo from './components/todo'



function app() {
    const [todos, settodos] = usestate([
        {
          id: 1,
          title: 'this is first list'
        },
        {
          id: 2,
          title: 'this is second list'
        },
        {
          id: 3,
          title: 'this is third list'
        },
    ]);

return (
        <div classname="app">
            <h1></h1>
            <todo todos={todos}/> //this is how i'm passing props in parent component
        </div>
    );
}

export default app;

then use the props in child component like below shown

function todo(props) {
    return (
        <div>
            {props.todos.map(todo => { // using props in child component and looping
                return (
                    <h1>{todo.title}</h1>
                )
            })}
        </div>  
    );
}


Related Query

More Query from same tag