Questions tagged [react-class-based-component]

230 questions
0
votes
1 answer

how to convert class component to function component with hooks in reactjs

My Code in Class Component I am still new to learning React and I am having a tough time converting class components into functional components. class App extends React.Component { handleChange = (e) => { const { name, value } = e.target …
0
votes
0 answers

how to transfer RecyclerListView from class component to functional

I faced RecyclerListView for the first time in legacy code, so I needed to rewrite that in functiona style, but when React tries to return RecyclerListView, programm freezes and do not even enter renderBetItem function, console.log doesn`t even…
0
votes
1 answer

React-native dark theme in class based project

i am having trouble adding a dark-theme support to my react-native app. theme-context.js import React from 'react'; const themes = { dark: { backgroundColor: 'gray', backgroundCard: '#25282c', color: 'white' }, …
0
votes
1 answer

Can't convert class to function component, "unmounted error"

Quick foreword: If you are rushing new posts, please move on instead of marking this as a duplicate as I really need help. Apologies if I sound harsh but I've been through this too many times. I am facing trouble converting the following component…
crimsonpython24
  • 2,223
  • 2
  • 11
  • 27
0
votes
1 answer

Converting react class component to functional component, rendering perfectly but functionality lost?

I am making a small audio player application and attempting to convert my react class component into a functional component. The original code for the class component is here: class Player extends React.Component { constructor(){ super() …
0
votes
1 answer

React class component issue in order of execution

I have the following code in my React class component. For some reason, I am observing that, inside componentDidMount, despite having the keyword await before the call to this.getKeyForNextRequest(), the execution is jumping to the next call,…
copenndthagen
  • 49,230
  • 102
  • 290
  • 442
0
votes
1 answer

Context undefined in constructor - react

export default class Printer extends React.PureComponent { static contextType = PrinterContext; constructor(props: PrinterProps, context: PrinterInterface){ super(props, context); this.PrinterInfo =…
0
votes
1 answer

Changing properties of a state using a function within React.js class component

I have a basic audio playing app using react-h5-audio-player. In its basic form, the AudioPlayer component takes a source, I have stored this media locally and am attempting to build a parent Player component around AudioPlayer as a parent that…
0
votes
1 answer

Reload render function after componentDidMount is loaded

I am trying to load ecwid store on my react.js website. I have created a class component where there is a function called load ecwid. I have put the function in the componentDidMount(). The console logs tell me the function is loaded well and good.…
0
votes
0 answers

React-Native: When to use Class- or Functional-Components?

I am pretty new to react/react-native and want to develope my first app. During programming I saw that there are two diffrent ways to declare a component. As I understood I always have to use class-components, if I want to access state variables.…
0
votes
1 answer

How to get params id in react class component

I want a params id from the url in this class component App.js Products.js import React, { Component }…
0
votes
2 answers

When calling a method in a react class component from a react functional component, is the state visible?

I'm building a react application and I'm encountering the following problem: I have a blog. The blog is implemented with a class component like this: class Blog extends Component { constructor() { super(); this.state = { …
0
votes
1 answer

How to add a prop from a functional component into a class component?

I have a prop "language" that comes from my LanguageFlag component that inserts a SVG icon depending on the language (shown below). In a normal functional component I would pass the language through a prop in and then add it in the component as…
0
votes
2 answers

I want the combined functioanlity of ComponentDidMount and ComponentDidUpdate in React js

I am fetching API data using axios and that API has query parameter (e.g.: searchQuery, which is defined in state). I have declared it's initial value in state and axios call in componentDidUpdate. Now I want my user to input the data in the form…
0
votes
1 answer

Question about react class component setState

I don't understand this part of the code: this.setState({ usernameValid, errorMsg }, this.validateForm); If we are updating usernameValid, errorMsg in the state, what does this.validateForm do? Because we are writing this outside the object of…
Amaan Imtiyaz
  • 254
  • 6
  • 16