Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
BlueChinchillaEatingDorito

Passing prop from App.js

Recommended Posts

Posted · Original PosterOP

I'm having some trouble accessing a prop from within the History page I'm making using React. In App.js I'm passing user as a prop.

<Route exact path="/history" render={(props) => (
		<History user={user}/>
		)} />

 

user is returned during componentDidMount:

    componentDidMount() {
        const user = AuthService.getCurrentUser();
        if (user) {
            this.setState({
                user: user
            });

The interesting fact is that I have another component before History :

<HeaderBar user={user}/>

And within the HeadBar component, it's able to access the user prop without any problems. However, in History, when I log this.props.user in the constructor, I'm constantly getting undefined. I made sure I have super(props) in the constructor so I'm at a lost right now. What could I be missing that's preventing me from passing the user prop?

 

So right now in History I have:

class History extends React.Component {
    constructor(props) {
        super(props);
        console.log(this.props.user)

 

If I add a button within render that logs this exact item, it logs it perfectly. The problem is that I need to use this user information to fetch whatever is going to be rendered on the page. 


AMD Phenom™ II X6 1100T @ 4.0GHz | MSI 890FXA-GD65 | MSI GTX 550Ti | 16GB Kingston DDR3 | Samsung 850 EVO 250GB | WD 750GB | Antec 300 | ASUS Xonar DG | Corsair A50 | OCZ 600W | Windows 10 Pro

Sony MDR-V250 | Logitech G610 Orion Brown | Logitech G402 | Samsung C27JG5 

Intel Core™ i5-8520U | WD Blue M.2 250GB | 1TB Seagate FireCuda | 8GB DDR4 | Windows 10 Home | ASUS Vivobook 15 

Intel Core™ i7-3520M | GT 630M | 16 GB Corsair Vengeance DDR3 | Samsung 850 EVO 250GB | macOS Catalina  Lenovo IdeaPad P580

AMD Phenom™ II X2 550 @ 3.10GHz | Gigabyte GA-MA785GM-US2H | XFX Radeon HD 4870 | 4GB Corsair XMS2 | WD 250GB | Thermaltake TR2 500W | Windows 10 Pro

iPhone 6s (iOS 13.6.1) | iPad Mini (iOS 9.3.5) | Samsung Galaxy S5e

Link to post
Share on other sites
Posted · Original PosterOP
3 hours ago, elpiop said:

Edit: Never mind :d

All good. Got it all figured out! Ended up making a workaround by calling the authenticator service again to retrieve the user information again from localstorage


AMD Phenom™ II X6 1100T @ 4.0GHz | MSI 890FXA-GD65 | MSI GTX 550Ti | 16GB Kingston DDR3 | Samsung 850 EVO 250GB | WD 750GB | Antec 300 | ASUS Xonar DG | Corsair A50 | OCZ 600W | Windows 10 Pro

Sony MDR-V250 | Logitech G610 Orion Brown | Logitech G402 | Samsung C27JG5 

Intel Core™ i5-8520U | WD Blue M.2 250GB | 1TB Seagate FireCuda | 8GB DDR4 | Windows 10 Home | ASUS Vivobook 15 

Intel Core™ i7-3520M | GT 630M | 16 GB Corsair Vengeance DDR3 | Samsung 850 EVO 250GB | macOS Catalina  Lenovo IdeaPad P580

AMD Phenom™ II X2 550 @ 3.10GHz | Gigabyte GA-MA785GM-US2H | XFX Radeon HD 4870 | 4GB Corsair XMS2 | WD 250GB | Thermaltake TR2 500W | Windows 10 Pro

iPhone 6s (iOS 13.6.1) | iPad Mini (iOS 9.3.5) | Samsung Galaxy S5e

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×