How to pass values between pages in react via URLS (Query string)

Hello,

How to pass values from a component to another component in react?

thanks

hey @lingo1357,

You do this with props https://reactjs.org/docs/components-and-props.html

function Child({ name }) {
  return <h1>Hello, {name}</h1>;
}

function Parent() {
    return (
     <div>
       <Child name="tom" />
     </div>
   )
}

Class component

class Child extends React.Component {
  render() {
    return <h1>This is array, {this.props.data}</h1>;
  }
}

class Parent extends React.Component {
    state = {
        data: [1,2,3,4,5]
    }
  render() {
    return (
      <div>
       <Child data={this.state.data} />
     </div>
   )
  }
}

I mean via URL passing (query string). Is it possible?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.