score:3
What happens here is that you have an object with properties.
There is a few things you can do.
You can show the properties you want
Instead of trying to render the full component, you can render some prop of it
{this.state.search === "" ? allStudents : this.state.filteredStudents.email} // render the email string
What you can also do is loop over the values of the object (Object.values
) and render each property
{this.state.search === "" ?
allStudents :
this.state.filteredStudents.map(obj => Object.values(obj)
.map(propValue => <p>{propValue}</p>)) // render the value of each property
}
But please, be more clear on your question, how you want to display, what you want to display and what you have in your component.
Just keep in mind that this.state.filteredStudents
is an object and you can't render objects.
score:0
I think error happened because variable allStudents is not a React object.
constructor() {
this.state = {
filterValue: ''
}
}
render() {
const students = [
{city: '', company: '', email: '', firstName: '', grades: '', id: '', lastName: '', pic: '', skill: ''}
] // <-- this is your array of students
const allStudents = students.filter(student => {
return student.firstName.includes(this.state.filterValue) ||
student.lastName.includes(this.state.filterValue)
}) // <-- Apply filter
.map(student => {
return (
<div key={student.key}>
<p>Name: {student.firstName} {student.lastName}</p>
<p>Email: {email}</p>
</div>)
}); // <-- Wrap each element into React Component
return (<div className="container">
<input
id="search"
name="search"
onChange={this.handleInput}
placeholder="Search by name"
style={{width: '100%', border: '0', padding: '15px 0 7px 10px'}}
value={this.state.filterValue}
/>
<hr />
{allStudents}
</div>)
}
Source: stackoverflow.com
Related Query
- Uncaught Invariant Violation: Objects are not valid as a React child
- Uncaught Invariant Violation: Objects are not valid as a React child (found: object with keys {$$typeof, render})
- React Hooks -- Uncaught Invariant Violation: Objects are not valid as a React child
- Uncaught Invariant Violation: Objects are not valid as a React child. If you meant to render a collection of children, use an array instead
- react-dom.development.js:55 Uncaught Invariant Violation: Objects are not valid as a React child (found: object with keys
- Uncaught Error: Objects are not valid as a React child . If you meant to render a collection of children, use an array instead
- Uncaught Error: Objects are not valid as a React child (found: object with keys {todo}). If you meant to render a collection of children, use an array
- Invariant Violation: Objects are not valid as a React child
- How to debug this error: Uncaught (in promise) Error: Objects are not valid as a React child
- Invariant Violation: Objects are not valid as a React child (for nested objects)
- Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead
- ReactJs 0.14 - Invariant Violation: Objects are not valid as a React child
- React Invariant Violation: Objects are not valid as a React child
- Invariant Violation: Objects are not valid as a React child when firing a function
- React : Invariant Violation: Objects are not valid as a React child
- Objects are not valid as a React child (found: object with keys {username}). If you meant to render a collection of children, use an array instead
- Error: Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {name}). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {job}). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: [object Element]). If you meant to render a collection of children, use an array instead.- ReactJs
- React.Js 0.14 - Invariant Violation: Objects are not valid as a React child
- Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead. ReactJS
- Objects are not valid as a React child (found: object with keys {totalItems}). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {arr}). If you meant to render a collection of children, use an array instead
- Error: Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead. JS
- react matrerial ui Error: Objects are not valid as a React child If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {weight}). If you meant to render a collection of children, use an array instead
- Uncaught Error: Objects are not valid as a React child (found: [object HTMLImageElement])
- Uncaught Error: Objects are not valid as a React child when trying to render html in react
More Query from same tag
- How to find a React component inside an element with specific class using enzyme?
- mapping a nullish object gives typescript error
- Typescript type checking error how to fix in React
- React.js - Separate the JSON return with pagination
- material-table tableRef.current value remains undefined
- "Cannot read property 'map' of undefined" when trying to map out state and pass it as props into component
- Formik Field not clearing after form submit
- When testing, code that causes React state updates should be wrapped into act(...)
- How to use Filter with ReactJS to prevent duplicates in an array from being displayed
- Not able to parse object id in link
- What is a reasonable size / order of magnitude for code splitting
- React TypeScript get Data Attribute From Click Event
- On Click of a Button made in one component is not changing value in other component in React.js
- semantic ui react Setting dropdown value to state
- ReactJS : Uncaught SyntaxError: Unexpected identifier error that only occurs temporarily
- Is functional component cause memory issue?
- JS functions error using Firebase and React
- Typing mapStateToProps React Redux
- react-map-gl: uncaught ReferenceError: _typeof is not defined
- MUI Autocomplete (multiple) controlled values - mysterious input behavior
- When I set state via useState in parent component, my props in the child I'm passing down to are undefined
- useState didn't seem to work with socket io
- ReactJS: Child Component is not updating even I am passing different values
- Passing ref to child component to animate with GSAP
- Unit Testing React HashRouter with Jest
- Dropdown React & Redux
- Trying to use multiple component for a single path
- Using Hooks along with Redux---Bad Practice?
- How to connect and get the balance from a Metamask wallet on the Polygon chain in React.js
- Idiomatic way to append an element in JSX