Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My Stateless Component not rendering (Reactjs and Redux)

Tags:

reactjs

redux

For some reason or another, my allEmployees stateless component isn't being rendered and I can't figure out why. I'm getting the following warning:

Unknown prop employeesData on <allEmployees> tag. Remove this prop from the element.

Container

class employeeListPage extends React.Component {
 constructor(props) {
 super(props);
 this.state = {
    employees : {}
 };
}

render(){
  return(
    <div>
        <allEmployees employeesData = {this.props.employees} />
    </div>
  )
}

}
function mapStateToProps(state, ownProps){
 return{
    employees: state.employees
}
}

function mapDispatchToProps(dispatch){
 return {
    employeeActions : bindActionCreators(employeeActions, dispatch)
 };
}

export default connect(mapStateToProps, mapDispatchToProps )(employeeListPage);

allEmployees Component

 const allEmployees = (props) => (
    <div>
     <table>
      <thead>
        <tr>
             <th>Employee Number</th>
             <th>Employee Full Name</th>
             <th>Active Employee</th>
             <th>Origin</th>
             <th>Modify</th>
             <th>Remove</th>
        </tr>
     </thead>
      <tbody>
      {props.employeesData.map( employee => {

                 <tr>
                    <td>{employee.Number}</td>
                    <td>{employee.FullName}</td>
                    <td>{employee.IsActive}</td>
                    <td>{employee.Origin}</td>
                    <td><button>Modify</button></td>
                    <td><button>Remove</button></td>
                 </tr>
      })};
      </tbody>
     </table>
    </div>

);

export default allEmployees;
like image 430
user3162979 Avatar asked Dec 21 '25 17:12

user3162979


1 Answers

When it comes to the warning, have a look at the official React guidance: https://facebook.github.io/react/warnings/unknown-prop.html

This may also be caused by a recent library update. Try using a previous version. More info here: https://stackoverflow.com/a/38177862/4186037

Also, in order to render React components, their names need to start with an upper-case letter: https://facebook.github.io/react/docs/jsx-in-depth.html#html-tags-vs.-react-components

Here is a demo showing that a component starting with a lower-case letter (article2) will not render: http://codepen.io/PiotrBerebecki/pen/YGxRqq

class App extends React.Component {
  render() {
    return (
      <div>
        <Article1/>
        <article2/> 
      </div>
    );
  }
}


// this component will render as it starts with a capital letter
class Article1 extends React.Component {
  render() {
    return (
      <div>
        Article1
      </div>
    );
  }
}


// this component will not render as it starts with a lower case letter
class article2 extends React.Component {
  render() {
    return (
      <div>
        article2
      </div>
    );
  }
}          


ReactDOM.render(
  <App />,
  document.getElementById('app')
);
like image 67
Piotr Berebecki Avatar answered Dec 24 '25 10:12

Piotr Berebecki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!