Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connectToBirst() only works with stateless components? #7

Closed
JesseSingleton opened this issue Jan 23, 2018 · 1 comment
Closed

connectToBirst() only works with stateless components? #7

JesseSingleton opened this issue Jan 23, 2018 · 1 comment

Comments

@JesseSingleton
Copy link

Hey Steve, hope things are well.

I'm currently trying to port the Bodymap into a reusesable birst widget, and I'm having an issue when I try and use connectToBirst(createQuery(parameters))(BodyMapComponent).

If BodyMapComponent is a stateless component it works fine but I'm getting to a point where I think need to be able to deal with state and when I make it into a class I get the following error:

ERROR in [at-loader] ./src/BodyMap/createConnectedBodyMap.tsx:38:60
        TS2345: Argument of type 'typeof BodyMapContainer' is not assignable to parameter of type 'ComponentType<{ bodyParts: IBodyPart[]; } & { applyDrillDown(drillDown: IDrillDown): any; }>'.
      Type 'typeof BodyMapContainer' is not assignable to type 'StatelessComponent<{ bodyParts: IBodyPart[]; } & { applyDrillDown(drillDown: IDrillDown): any; }>'.
        Type 'typeof BodyMapContainer' provides no match for the signature '(props: { bodyParts: IBodyPart[]; } & { applyDrillDown(drillDown: IDrillDown): any; } & { children?: ReactNode; }, context?: any): ReactElement<any> | null'.
webpack: Failed to compile.

A quick get around is to replace BodyMapComponent with a stateless component wrapping BodyMapComponent and this passes down the props, but obviously that feels a little wrong and I think this might be causing some issues with trying to pass through other HTMLparameters.

Here's my BodyMapContainer component just in case I'm doing anything obvious:

import * as React from 'react';
import { IBodyPart } from '../IBodyPart';
import { BodyPart } from './BodyPart';
import { BodyMap } from './BodyMap';
import { Thumbnail } from './Thumbnail';
const css = require('../bodyMap.less');

export interface IBodyMapContainerProps {
	bodyParts: IBodyPart[];
	imageUrls: string;
};

interface IBodyMapContainerState {
	backgroundImage: string;
}

export class BodyMapContainer extends React.Component<IBodyMapContainerProps, IBodyMapContainerState> {
	constructor(props: IBodyMapContainerProps) {
		super(props);
	}
	
	updateImage = (backgroundImage: string) => {
	//Does something
	};

	render() {
		return (
		<div className='image-map-container'>
		<div className='thumbnails'>
			<Thumbnail onChange = { this.updateImage } backgroundImage = './Images/body-map-front.png'/>
			<Thumbnail onChange = { this.updateImage } backgroundImage = './Images/body-map-back.png'/>
		</div>
			<svg className='image-map-svg' >
				<BodyMap
					{...this.props}
				>
				</BodyMap>
			</svg>
		</div>
		)
	}
}

export default BodyMapContainer;
@stevegreatrex
Copy link
Owner

stevegreatrex commented Jan 23, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants