при использовании модульности css файлов в компоненте возникают проблемы при обращении в JS к нужному классу.
class Example extends React.Component {
state = {
shouldShowMenu: false,
};
handleToggleMenuClick = () => {
this.setState(state => ({
shouldShowMenu: !state.shouldShowMenu,
}));
};
render() {
const { shouldShowMenu } = this.state;
return (
<div>
<button onClick={this.handleToggleMenuClick}>Toggle menu</button>
{shouldShowMenu && <Menu />}
</div>
);
}
}
export default function reducer(state = {}, action) {
import search from "./search-reducer";
const initialState = {
value: "",
works: [],
};
export default function search(state = initialState, action) {
import React, { useState, useCallback } from 'react';
import { Icon, Hint } from '../some-place';
const Example = () => {
const [shouldShowHint, setShouldShowHint] = useState(false);
const onMouseEnter = () => useCallback({
setShouldShowHint(true);
}, []);
const onMouseLeave = useCallback(() => {
setShouldShowHint(false);
}, []);
return (
<div
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
>
<Icon />
{shouldShowHint && <Hint />}
</div>
);
};
const initialState = {
tip: null,
isFetching: false,
errors: {},
};
case FETCH_VIDEO_TIP_FAILED:
return {
...state,
isFetching: false,
errors {
[payload.slug]: payload.error,
},
};
const mapStateToProps = (state, ownProps) => ({
error: state.videotips.errors[ownProps.match.params.slug],
});
const mapStateToProps = (state) => ({
error: state.videotips.errors.homepage,
});
{items.map(item => (
<CardImg key={item.picture} top width="100%" src={item.picture} alt={item.imgalt} />
))}
<List>
{data.map(item => <Item key={item.id} item={item} />)}
</List>
function defaultEqualityCheck(a, b) {
return a === b
}
class Example extends React.Component {
state = { filter: 'all' };
componentDidMount() {
this.props.fetchData(this.state.filter);
}
componentDidUpdate(prevProps, prevState) {
if (prevState.filter !== this.state.filter) {
this.props.fetchData(this.state.filter);
}
}
render() { /* ... */ }
}
prevProp === prop