Questions tagged [react-class-based-component]

230 questions
1
vote
1 answer

'Save Palette' button gives a TypeError of 'savePalette' is not a function

My 'NewPaletteForm' is a functional component as I've used react hooks. So when I click the button 'Save Palette', an error occurs which says 'props.savePalette is not a function'. ERROR:- TypeError: props.savePalette is not a…
1
vote
1 answer

Convert Uncontrolled Components from : Class extends to Functional Components?

I'm getting trouble in converting the Uncontrolled Components from class Components into Functional Componnents... Class Components: import React from 'react'; class NameForm extends React.Component { constructor(props) { super(props); …
1
vote
1 answer

Converting Functional Component code to Class Component code

I'm new to Functional Components in React and was wondering how I would convert the code below from functional based to class based. I have had a go but I've had troubles around "React.useEffect". Any help would be greatly appreciated! :) (Also a…
1
vote
1 answer

Rerender React child component with a complex/nested state update

Below is a sample version of my actual code. // parent component this.state = { ..., dummies: [ {id: 1, name: "nothing"}, {id: 2, name: "nothing"}, {id: 3, name: "nothing"} ], ... }; render(){ return
Greenhorn
  • 580
  • 6
  • 20
1
vote
1 answer

How do I prevent user from entering a username that starts with a number, but allow numbers only after alpha characters?

I have this code bellow and my trouble is when I want to check whether user has entered a number in front using startsWith() function, I get a "TypeError: usernameField.startsWith is not a function". How do I prevent user from entering a username…
1
vote
1 answer

Should I use global variables for keeping the session of the current user in react native?

Currently I'm working on a React Native app which requires people to login to the application, I've created the login page, server-side authentication, etc. My question is, how can I save the user login information in the client-side in a manner…
1
vote
0 answers

react shouldComponentUpdate new and old props same

In my code there is one child component that receives props from parent which I'm mapping that array for render their name, add image button and one child's child component for render images (this is for avoiding rerendering images). When I add an…
Deep Patel
  • 70
  • 7
1
vote
1 answer

How to implement global variable in react functional components

I am new to react and decided to practice by implementing a simple stop watch using both class and functional components. I successfully implemented the stop watch using a class component. Below is the code: Class Component class Stopwatch extends…
1
vote
2 answers

React context value not available in child class component

I have declared a React context in indexa.js and I'm trying to access the context value set in App.js in Employee.js. But it's not rendering the value I'm new to React. Please help me out. Thanks in advance //index.js export const employeeContext =…
1
vote
1 answer

How to animate the disappearance of a component in ReactJS?

In my react App I have a class-based parent component Items. Inside it renders the child component Item. export class Items extends Component { render() { return (
1
vote
1 answer

Difference in accessing props after change in redux store between React class component and React functional component

I`m having a problem in understanding why in a Class based component vs Functional component the same steps yield a different result. Below I have an example that presents this difference. class Test extends Component { handleSubmit = e =>…
1
vote
2 answers

Problem related to calling functional components in ReactJS

On running the react webpage h1 first is being printed but h1 second is not being printed Moreover renderDishDetail and renderComments are not being called. I am new in ReactJS and was learning about functional components. I converted my class…
1
vote
1 answer

Accessing functional component's methods from the 'outside'

Let's say that I want to control the loading state of my app by calling the method from outside of the app like so: setLoading(true) I have implemented a functional component for which something like that works: import React from 'react'; function…
1
vote
2 answers

Filtering content based on query string using React Js

We have a simple react app.. Data is coming from an api and stored in the state. Then we use a map function to render the data. And use sort and filter functions to manipulate the data. Now, we are trying to associate the filter information with the…
Jasmohan Singh
  • 61
  • 3
  • 11
1
vote
3 answers

React: change from class based components to functional based components

This is a react beginners exercise so I'm looking for the simplest solution. I need to convert these 3 class components into functional components. I'm currently learning React so any helpful comments would also be appreciated. Thanks in…