General rules for working with react
Instead of
<Button onClick={() => this.props.onAction(this.props.id)} />Use
method () {
this.props.onAction(this.props.id)
}
/* ... */
<Button onClick={this.method} />component.styles.ts
import styled from "styled-components";
export const Wrapper = styled.div`
display: flex;
`;
export const Modal = styled.div`
width: 240px;
height: 250px;
`;
export const Text= styled.p`
font-size: 16px;
`,
};component.ts
import * as Styled from './component.styles.ts';
/* ... */
<Styled.Wrapper>
<Styled.Modal>
<Styled.Text/>
</Styled.Modal>
</Styled.Wrapper>export const User = (props) => <div {...props} />;Instead of
render () {
<Component>
{data.map((d) => <User {...d} />)}
/* ... */
/* ... */
/* ... */
</Component>
}Use
render () {
<Component>
<UserList users={data.users} />
<Info currentUser={this.currentUser()} />
</Component>
}in state file
const onUpdateUser = (value: string, option: string) => {
setState((s) => ({
...s,
user: {
...s.user,
[option]: value,
},
}));
};in input component
interface IProps {
option: string;
value: string;
onUpdateUser: (value: string, option: string) => void;
}
/* ... */
const onChangeText = (text: string) => {
props.onUpdateUser(text, props.option);
};