handleNoteDel = index => {
const notes = [...this.state.notes];
notes.splice(index, 1);
this.setState({ notes });
}
handleNoteDel = index => {
this.setState({
notes: this.state.notes.filter((_, i) => i !== index),
});
}
import { render } from 'react-dom';
import {createStore} from "redux";
import rootReducer from "../reducers";
import Auth from './components/Auth';
const store = createStore(rootReducer);
render(
<Provider store={store}>
<BrowserRouter>
<Auth />
</BrowserRouter>
</Provider>,
document.getElementById('root'),
);
import React, {Component} from 'react';
import {connect} from 'react-redux';
class Auth extends Component {
render() {
return (
<Switch>
<Route exact path={this.props.api.signin} render={() => Test}/>
</Switch>
);
}
}
const mapStateToProps = state => ({
api: state.api,
});
export default connect(mapStateToProps)(Auth);
getPromoUrl = async (id, param) => {
const data = await this.getPromise(id, param);
console.log(data);
this.setState({ data });
};
getPromoUrl = (id, param) => {
this.getPromise(id, param).then(data => {
console.log(data);
this.setState({ data });
});
};
const getColor = value => {
switch(value) {
case 20:
return 'orange';
case 50:
return 'blue';
}
}
render() {
const { value } = this.props;
return <ExampleComponent style={{ color: getColor(value) }} />;
}
Как через рекурсию получиться произведение массива.
const result = array.reduce((acc, el) => acc * el);
Предполагается , что значение массива изначально не известно .
Вот примерный набросок, но у меня ничего не выходит.
declare module 'koa-connect-flash' {
const def: any;
export default def;
}
const fetchUsers = params => async dispatch => {
try {
const data = await Api.fetchUsers(params);
dispatch(fetchUsersSuccess(data));
} catch (e) {
dispatch(fetchUsersFail(e));
}
}