I'm having trouble with React by being unable to pass my props to child components. I've read the documentation but I'm still confused as to what steps need to be taken. This is done using Ruby on Rails with the react_on_rails gem. At this point, Redux is not in use and I'm still learning the ropes with React.
I'm sending in a variable from rails using react_component with the following:
index.html.erb
<%= react_component('Lifts', props: @lifts, prerender: true) %>
Trying to pick it up in React. The data shows up under the Elements section of the Chrome dev tools. But, I'm assuming that maybe I'm not binding the data properly. Nothing seems to show up in LiftsList.jsx. Perhaps the solution is obvious but it's really escaping me right now.
Lifts.jsx
import React, { PropTypes } from 'react';
import LiftsList from './LiftsList';
import Lift from './Lift';
export default class Lifts extends React.Component {
constructor(props, _railsContext) {
super(props);
this.state = {
id: props.id,
date: props.date,
liftname: props.liftname,
weightlifted: props.weightlifted,
repsformed: props.repsformed,
}
}
render() {
return (
<div className="container" style={{display : 'inline-block'}}>
<ul>
<LiftsList lifts = {this.state.lifts} />
</ul>
</div>
);
}
}
LiftsList.jsx
import React, {PropTypes} from 'react';
import Lift from './Lift';
export default class LiftsList extends React.Component {
render() {
let lifts = this.state.lifts.map(lift =>
<Lift key={prop.id} {...lift} />);
return (
<div>
<div>???</div>
</div>
);
}
}
Lift.jsx
import React, {PropTypes} from 'react';
export default class Lift extends React.Component {
render() {
return (
<ul>
<li>{this.props.id}</li>
<li>{this.props.date}</li>
<li>{this.props.liftname}</li>
<li>{this.props.ismetric}</li>
<li>{this.props.weightlifted}</li>
<li>{this.props.repsformed}</li>
</ul>
);
}
}