score:4
Accepted answer
you have several mistakes
you should pass
onclick
totopicslist
render() { return ( <div classname="row"> {this.state.istopicclicked ? <selectedtopicpage topicsid={this.state.topicsid} key={this.state.topicsid} topicpages={topicpages} /> : <topicslist onclick={ this.onclick.bind(this) } />} </div> ); }
remove
onclick
method fromtopicslist
onclick() { // ... },
pass
onclick
callback fromprops
<singletopicbox topicid="1" onclick={this.props.onclick} label="topic"/>
add to
singletopicbox
onclick
event<div classname="single-topic" data-topic-id={this.props.topicid} onclick={ () => this.props.onclick(this.props.topicid) } > {this.props.label} {this.props.topicid} </div>
you don't need call
setstate
twiceonclick(topicid) { this.setstate({ istopicclicked: true, topicsid: topicid }); }
Source: stackoverflow.com
Related Query
- React - uncaught TypeError: Cannot read property 'setState' of undefined
- react router v^4.0.0 Uncaught TypeError: Cannot read property 'location' of undefined
- React with ES7: Uncaught TypeError: Cannot read property 'state' of undefined
- Uncaught TypeError: Cannot read property 'toUpperCase' of undefined react state item
- React - Uncaught TypeError: Cannot read property 'func' of undefined
- Uncaught TypeError: Cannot read property 'value' of undefined in REACT JS
- Uncaught TypeError: Cannot read property 'map' of undefined with React
- Uncaught TypeError: Cannot read property 'state' of undefined - React
- React JS - Uncaught TypeError: Cannot read property 'bind' of undefined
- React Js Uncaught (in promise) TypeError: Cannot read property of undefined
- React v16: Uncaught TypeError: Cannot read property 'object' of undefined
- react js mapStateToProps triggers Uncaught TypeError: Cannot read property 'map' of undefined
- Uncaught TypeError: Cannot read property 'length' of undefined , using react and redux-form validation
- Error: Uncaught [TypeError: Cannot read property 'x' of undefined Jest react testing
- React Uncaught TypeError: cannot read property x of undefined
- React Uncaught TypeError: Cannot read property 'replace' of undefined
- Uncaught TypeError: Cannot read property 'then' of undefined in React ajax Call?
- Uncaught TypeError: Cannot read property 'history' of undefined !! React router
- React browserHistory.push giving Uncaught TypeError: Cannot read property 'push' of undefined
- React - Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
- Uncaught TypeError: Cannot read property 'map' of undefined - React js
- React Redux - Uncaught (in promise) TypeError: Cannot read property 'props' of undefined
- React - Uncaught TypeError: Cannot read property "name' of undefined using Airtable
- React + Axios: Uncaught (in promise) TypeError: Cannot read property 'map' of undefined
- Uncaught TypeError: Cannot read property 'name' of undefined in React
- Uncaught TypeError: Cannot read property 'active' of undefined in React
- Uncaught TypeError: Cannot read property 'forEach' of undefined in javascript / React-router / React
- React & firebase- uncaught TypeError: Cannot read property 'setState' of undefined
- React Js Context Uncaught (in promise) TypeError: Cannot read property 'data' of undefined
- React - Uncaught TypeError: Cannot read property 'Component' of undefined
More Query from same tag
- How to render nested map from JSON in React.JS?
- passing foreign key id in the next page state
- How to call a function onClick which is defined in React Hooks useEffect()?
- How to access a registered workbox queue in my React application
- Drawer is overlapping Navbar in react material ui app, do you know how to change?
- How to add points dynamically like this "..." to indicates that there are more pagination buttons
- can't access object's properties within object in react
- How to implement different hover effect for the links as shown in the code?
- Initializing state in constructor versus state
- Inline eslint comment in JSX
- I want to write a test which checks that the component displaying a blog renders the blog's title and author,
- How to shorten a long line of code? Error ESlint
- What does it mean when there are two functions with the 'arrow function indicator' between them?
- Id conflicts for displayed records using react redux
- React storing prop value from outcome of loop
- How to pass form data to MongoDB in React?
- Using an API to create data in a React-Table
- Arcgis builder custom widget to get specific field and value from user to filter the data
- Is it safe to edit same piece of state with two dispatches in a row
- React initial state. counting
- 'ref' is not defined no-undef I would like to try to load image from firebase storage
- Passing in types properly to Redux reducer
- how to make a dispatch wait for the first dispatch to run
- Swiperjs in React : swiper.slideTo TypeScript
- How can I match if the current route matches a pattern in React Router Dom v6?
- How do I mock a const method IN a component as part of an integration test?
- Fluent UI style not working in passed commands with buttons to CommandBar
- React, Firebase: Auth possibly failing on redirect
- How to specify class on a JSX node?
- React setState with callback and pass props