I
I
Igor N.2018-09-15 14:47:32
Frontend
Igor N., 2018-09-15 14:47:32

React + TypeScript: how to pass a parameter to a component's render()?

The component uses a decorator that needs to be passed to render:

class Preloader extends PureComponent<IPreloader, undefined> {
    //...
    render(cn: ClassDecorator) {
    //...
    }
}

, above defined interface:
export interface IPreloader {
  size?: string;
  active?: boolean;
  color?: string;
  render: (cn: ClassDecorator) => any;
}

But TS swears at him:
TS2415: Class 'Preloader' incorrectly extends base class 'PureComponent'.
Types of property 'render' are incompatible.
Type '(cn: ClassDecorator) => Element' is not assignable to type '() => ReactNode'.

Tell me how to correctly pass the decorator to the render?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Alekseev, 2018-09-15
@jmax

I think this article should help https://medium.com/@goncalvesjoao/react-es7-decora...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question