Questions tagged [react-class-based-component]

230 questions
0
votes
2 answers

react: Convert from Class to functional component with state

How would one convert the class component to a functional one? import React, { Component } from 'react' class Test extends Component { state = { value: "test text", isInEditMode: false } changeEditMode = () => { …
0
votes
2 answers

React Native: Functional Component to Class Component

I am using React Native Gifted Code. I am trying to convert the following example to class component: And here's is my code snippet provided below: constructor(props) { super(props); this.state = { message: [{ _id: 1, …
0
votes
1 answer

Class based component is not working as expected in ReactJs appication

I am trying to show the content of my class-based component in part of the functional component but it is not working. class-based component: class commentForm extends Component { render() { return(
0
votes
0 answers

React Constructor: "super" keyword is coming with a Strike through

I'm making a new react app and this happened with me for the first time. I am using class-based components for now. I was initializing a variable in this.state inside the constructor and caught up with this weird issue. Issue :Strike Through on…
0
votes
1 answer

Console.log is printing values twice in constructor and render function in React.js

Why console.log is printing values two times in constructor & render function? here it is: class App extends React.Component { constructor(props) { console.log('Constructor'); super(props) this.state = { counter: 0 } …
Shakir
  • 33
  • 4
0
votes
1 answer

React : Invalid hook in a class-based component that doesn't use a hook

I have some issues with React. I want to create a component library in the form of a class (I come from the Java world and I find the OOP more readable). For that, I made a base class from which all of my components will inherit. import { Box,…
Answerrer
  • 2,803
  • 4
  • 8
  • 18
0
votes
1 answer

How to update multiple child states in React Class Components independently?

I know how it can be done with Functional Components. But when it comes to class components, I'm having few questions to be clarified. I've a class here, class MyTable extends Component { constructor(props) { super(props); this.state…
Kishore Kumar Korada
  • 1,204
  • 6
  • 22
  • 47
0
votes
2 answers

How do I get the UI to render with my state with react

I have an onClick method to react that changes the state of a property named pointer. The function works on a functional level however the UI does not update with my state unless I double click the button (onClick method). I tried turning the…
0
votes
1 answer

How to refactor React mousemove Class to functional Component?

I have a button which closes a navigation. This button follows the mouse. Everything is working, but I have a depricationwarning, which I wanna get rid of, but don't know exactly how. (I only know that useEffect is playing a certain role: Here is…
0
votes
1 answer

Using data passed from parent to child classes for adding points on globe

I am working on a fun project, to help boost my knowledge and understanding of ReactJS coupled with ThreeJS, but have run into an issue for passing in data from the parent class to the functions in the child class. Right now my project looks as…
0
votes
1 answer

Difference between this two js in react

I start to learn React JS and anyone can explain me the difference between those two files? Both of them do the same thing. First JS import React, { useEffect, useState } from 'react' import Product from './Product'; import './Today.css'; import {…
0
votes
0 answers

React use-dark-mode deploying in component

The following development is in REACT. I'm using the use-dark-mode NPM package and I need some help with deploying it in a class component rather than a function. Any method I tried, I would get the "Hook can only be called inside of the body…
0
votes
1 answer

React - state doesn't update in class component even though the message printed on the screen changes

I have an App component which holds an input. Every time I type in the input, the value of the input updates and a Message component prints a different message, depending on how long the input is. At the same time, a third component called Character…
Kasia
  • 118
  • 3
  • 16
0
votes
2 answers

Limiting addEventListener to componentDidMount using useEffect hook

I have a class-based component which uses multitouch to add child nodes to an svg and this works well. Now, I am trying to update it to use a functional component with hooks, if for no other reason than to better understand them. In order to stop…
0
votes
2 answers

Convert a react class component to react hooks component

I want to convert this react class component into a react hooks component. I converted most of the code and now I need help to convert the part of code that is between the render and the return functions. Here is the class component: class…