Answer the question
In order to leave comments, you need to log in
OOP + React + typescript how to create components correctly?
Are there any examples of view components that have been written with typescript using OOP?
Answer the question
In order to leave comments, you need to log in
I write like this:
import * as React from 'react';
import { connect, DispatchProp } from 'react-redux';
import { connectedPropSelector } from './selectors';
interface OwnProps {
ownProp: string,
}
interface ConnectedProps {
connectedProp: string,
}
type Props = OwnProps & ConnectedProps & DispatchProp<any>;
interface State {
someKey: string,
}
class Example extends React.Component<Props, State> {
state = {
someKey: 'someValue',
};
render() {
const { ownProp, connectedProp } = this.props;
return ( /* ... */ );
}
}
const mapStateToProps = state => ({
connectedProp: connectedPropSelector(state),
});
export default connect(mapStateToProps)(Example);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question