Starting with Create React App 4, you can add asrc/service-worker.js
file to your project to use the built-in support for Workbox'sInjectManifest
plugin, which will compile your service worker and inject into it a list of URLs to precache.
const BaseComponent = styled.div`
color: black;
`;
const Component = styled(({ className, ...props }) => <BaseComponent calendarClassName={className} {...props} />)`
color: white;
`;
BaseComponent
распространяются на className
.Component
на calendarClassName
. useEffect(() => {
titleRef.current.addEventListener('keyup', addTodo); // <-- ???
return () => titleRef.current.removeEventListener('keyup', addTodo);
}, [])
return (
<> // <-- ???
<input
type="text"
value={ title }
onChange={ e => setTitle(e.target.value) }
ref={ titleRef }
/>
</> // <-- ???
);
function addTodo(e) {
if(e.keyCode === keyCodeEnter) { // <-- e.key === "Enter"
props.addTodoCreator({
title: title,
isCompleted: false,
color: 0,
});
}
}
const Header = ({ addTodoCreator }) => {
const [title, setTitle] = useState("");
const addTodo = (e) => {
if (e.key === "Enter") {
addTodoCreator({
title: title,
isCompleted: false,
color: 0,
});
}
};
return (
<input
type="text"
value={title}
onChange={(e) => setTitle(e.target.value)}
onKeyUp={addTodo}
/>
);
};
import { withRouter } from "react-router-dom";
class MyComponent extends React.Component {
...
render() {
const { history } = this.props;
...
}
}
export default withRouter(MyComponent);
history.push
- заменять не надо.withFormik()
https://jaredpalmer.com/formik/docs/api/withFormik. const [myToken, setMyToken] = useState(
localStorage.getItem("myToken")
);
const rootReducer = combineReducers({
propsReducer: reducer
});
const mapStateToProps = state => ({
onLike: state.propReducer.like
});
{stateToPropsStartDataArray &&
Object.keys(stateToPropsStartDataArray).map(element => (
<button
data-stateToPropsCategory={element}
onClick={e =>
onFilter({
stateToPropsCategory: e.target.dataset.statetopropscategory
})
}
className={
element === stateToPropsCategory ? "active" : "noActive"
}
>
{element}
</button>
))}
var newData = state.startDataArray[
action.stateToPropsCategory || state.category
].filter(x => {
return x["planeTypeID.code"]
.toLowerCase()
.includes(action.search || state.searchInput);
});
componentDidMount() {
if (this.props.users.length === 0) {
// запрос к api
}
}
import React, { Component, Fragment } from 'react';
import { connect } from 'react-redux';
import { personsFetchData } from '../Actions/persons';
// import { User, Headline, Paragraph, UserImage } from '../Website/Users/UsersStyles';
class PersonsData extends Component {
componentDidMount() {
this.props.fetchData('https://frontend-test-assignment-api.abz.agency/api/v1/users');
}
render() {
const { users } = this.props.persons;
return(
<Fragment>
{ users ? users.map(user => <div>{ user.name }</div>) : null }
</Fragment>
);
}
}
const mapStateToProps = state => ({
persons: state.persons.payload,
});
const mapDispatchToProps = dispatch => ({
fetchData: url => dispatch(personsFetchData(url)),
});
export default connect(mapStateToProps, mapDispatchToProps)(PersonsData);