0

Novice.

I am using react-redux and want to pass an Id value to another page.

I have a URL that supplies the "Id" value (eg 1029 as below) which I want to use in an action that has a fetch statement, again which utilises this "Id" value.

I cant seem to pass this "Id" value through to the compnentDidMount() function...

The URL looks like this:

http://localhost:3000/clients/edit/1029

My routes.js looks like this:

    import React from 'react';
    import { Route } from 'react-router';
      export default
          <Route component={Layout}>
            <Route path='/' components={{ body: Home }} />
            <Route path='/clients/edit/:id' components={{ body: EditClient }} />
          </Route>;

It successfully matches the route with ":id" and lands on the "EditClientContainer" Page.

...which has the function

componentDidMount() {
  this.fetchClient(id)
}

and the "fetchClient" function directly under it:

 fetchClient = (id) => {
  this.props.requestClient(id)
 }

I want the "id" from the URL to form the "Id" parameter in fetchClient.

How do I get the (in this case 1029) to become the parameter in fetchClient via the function "componentDidMount()"?

si2030
  • 3,895
  • 8
  • 38
  • 87
  • 1
    It should be within `this.props` context. Refer to this post https://stackoverflow.com/questions/35352638/react-router-how-to-get-parameter-value-from-url – mr.b Jul 23 '17 at 08:59
  • This was enough to get me over the line. I used " console.log('Props:', this.props)" to identify the prop for the Id and from there utilise the correct prop. Thanks – si2030 Jul 23 '17 at 10:42

0 Answers0