I have no absolutely idea how to pass state as props
havesomeleeway opened this issue · 1 comments
havesomeleeway commented
I recently switched to typescript but i'm having real difficulty having my Container
component render my dummy component by passing the state as props.
I have a dummy component here
import * as React from "react";
import { Button, Card, InputGroup } from "@blueprintjs/core";
import { Link } from "react-router-dom";
/** TypeScript Props from package, used for Input component **/
import { IControlledProps } from "@blueprintjs/core";
export interface LoginProps {
/** Form value of the input, for controlled usage. */
emailOrPhone: string,
/** Form value of the input, for controlled usage. */
onSubmit: React.FormEventHandler<HTMLElement>;
}
const LoginForm = (props: IControlledProps & LoginProps) => {
return (
<div>
<InputGroup
name="emailOrPhone"
type="email"
placeholder="Email or phone"
value={props.emailOrPhone}
onChange={props.onChange}
large
/>
</div>
<div>
<Button
rightIcon="arrow-right"
intent="primary"
large
onSubmit={props.onSubmit}
>
Next
</Button>
</div>
);
};
export default LoginForm;
And I have a container component that is supposed to subscribe to state from my store eventually, and render the component with the necessary props.
/src/container/Login
import * as React from 'react';
import LoginForm from "../components/login/LoginForm"
const initialState = {
emailOrPhone: ""
};
/** Prevents direct state manipulation */
type State = Readonly<typeof initialState>
class Login extends React.Component<State> {
readonly state: State = initialState;
render() {
return (
<LoginForm
onChange={this.handleEmailOrPhoneChange}
onSubmit={this.handleSubmit}
emailOrPhone={this.state.emailOrPhone}/>
)
}
private handleEmailOrPhoneChange = (evt: React.ChangeEvent<HTMLInputElement>) => {
this.setState({emailOrPhone: evt.target.value});
};
private handleSubmit = (evt: React.ChangeEvent<HTMLInputElement>) => {
evt.preventDefault();
};
}
export default Login
However, when I make an attempt to run the app, I am thrown this exception
Type error: Argument of type '{}' is not assignable to parameter of type 'T'. TS2345
100 | const definedObjB = objB == null ? {} : objB;
101 |
> 102 | const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys);
I'm really quite lost as to where I'm assigning an object {}
to a parameter of type 'T'
.
Any help would be very very much appreciated.
piotrwitek commented
The error you are showing is not relevant to the components above, cannot help you.
Please try on our gitter channel or SO.