Questions tagged [react-class-based-component]

230 questions
0
votes
2 answers

Not getting the expected output when using react hooks

I was converting react class components to functional components in one of my projects. This is the class component export default class App extends React.Component { constructor(props) { super(props); this.state = { user: null, …
0
votes
2 answers

Infinite loop while trying to implement debounce user search on input box react

I have the following app at https://github.com/codyc4321/dividends_ui on branch debounce_search_term. The server can be downloaded at https://github.com/codyc4321/stocks_backend. I have the following app which handle higher level information, the…
codyc4321
  • 9,014
  • 22
  • 92
  • 165
0
votes
2 answers

How to pass this.varible to HTML within class extends React.Component?

I am currently using the react-youtube library within one of my react objects. It contains some data that I would like to display on the screen. import YouTube from 'react-youtube'; class MediaCompnent extends React.Component { _onReady(event) { …
Kevin
  • 137
  • 1
  • 12
0
votes
1 answer

Params from React Router with class components and typescript

I have an application, that uses the class component syntax to create all components so far. With these package versions: "react": "^18.2.0", "react-dom": "^18.2.0", "react-router": "^6.3.0", "react-router-dom": "^6.3.0", "react-scripts":…
0
votes
1 answer

React 18 Router 6 - "Invalid hook call" when using Outlet with class components

I have recently upgraded a React project to 18 and it's dependencies: react-project package.json: "dependencies": { "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.3.0", "react-scripts": "5.0.1" }, "devDependencies": { …
0
votes
1 answer

Cannot access object specific properties via props in ReactJS

//Calling props value inside componentDidMountHere i am able to access the value of others but when i access widget.data i got indefined componentDidMount(){ const widget = this.props.widgets.filter(widget => widget.id ===…
0
votes
4 answers

how to convert a hook into class based component

I have a functional component which i used to detect outside click of the component and once that done i do some logic... now i had to use this inside a class based component My Hook useComponentVisible import { useState, useEffect, useRef } from…
0
votes
0 answers

Convert react function component to react class component

I am learning react and need some help from you guys. I wants need to convert my react hook function to react class component. React Hook ; const Card = () => { const [model, setModel] = useState(false); const [tempData, setTempdata] =…
0
votes
2 answers

Why square brackets used while creating dynamic state

I was following a tutorial and it used square brackets for updating the state in changeHandler function for [e.target.name]. Why do we have to use square brackets with e.target.name which is just a key of the state object. I tried using the…
user17043484
0
votes
1 answer

this.setState is not assigning a value to state, returning "undefined"

So I'm trying to assign a state to a parent class component from a child functional component. The issue I'm running into is that the state of the parent doesn't seem to be getting set with the value that is passed from the child component. When I…
0
votes
0 answers

React Unit Test for onChange | Class Component

I want to write unit test for these functions. enable () { this.setState({ show: true }); this.showValue(); } showValue () { const { model } =…
0
votes
1 answer

Rewrite react class into react hooks component

Started learning react hooks a while ago but I don't know much about React class based components. I might be asking for too much but could someone can help me rewrite this code into react hooks: import React from 'react' import axios, { post } from…
Marcus
  • 13
  • 3
0
votes
1 answer

Send props to parent from child | React class based Component

I have this in my Child Component. I want to use showTab state in its parent component. How do i send it to its parent? let enable = false; if (value) { enable = true; } this.state = { showTab: enable …
0
votes
1 answer

Pass const present in other function as a props | React class component

I have this view which is in the Controller, and item is passed as a prop. render () { if (this.view) { const { item } = this.props; return ; } } I have this other function…
0
votes
1 answer

Why my state is not getting set inside class based component and it should work but it is not neither i am getting error

The issue i am facing is i am not able to set my state in the class based component i don't know whats wrong with it i have created a very small project before this so that i can practice the state manipulation and i am doing the same way as test…
sarangkkl
  • 773
  • 3
  • 15