How extend a button component

UI Components for React
Post Reply
luca.stancapiano
Posts: 27
Joined: 18 Jun 2018, 14:52

06 Jul 2022, 08:20

Hello everybody. I am using primereact 8.1.0 and I would like to extend the primereact / button component. Once with version 7.2.0 it was easy, it was enough to do something like this inside the component:
CODE: SELECT ALL

Code: Select all

import {Button} from 'primereact / button'
export class Party extends Button {
....
}
If I try now I get the error:
TypeError: Super expression must either be null or a function, not object
Since I have very large classes and I would like to migrate from primereact 7 to 8 what is the quickest way to make the necessary corrections?

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

08 Jul 2022, 16:41

With React 8 all components are no longer Class components they are Functional Components which is the way React is going.

See StackOverflow on how to extend a Functional Component: https://stackoverflow.com/questions/416 ... -component
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

luca.stancapiano
Posts: 27
Joined: 18 Jun 2018, 14:52

10 Jul 2022, 08:21

you should try them first instead of sending links. Trying the example I get the same error.

Code: Select all

import { Button } from 'primereact/button'

class ExtendedButton extends Button {
}

var dq = new ExtendedButton();
console.log('test ' + dq.badge);

Uncaught TypeError: Super expression must either be null or a function



Do you have an example of how to extend a Button?

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

11 Jul 2022, 14:00

I sent links because the link explains why you CAN NOT do what you are trying to do with PrimeReact 8 and Functional Components.

You should read the links before posting a question about me not sending links....

Basically you CAN NOT do this "extends Button" anymore...you have to use composition (just like the link I posted explains).
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests