/
githubmirror
/
redux
Обзор
Документация
Войти
/
githubmirror
/
redux
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/real-world/src/containers/App.js
65 строк
1 KB
Tim Dorr
Format the examples
20 мар 2024, 19:52
Не верифицирован
20 мар 2024, 19:52
3085048
Код
Авторство
О чём код?
/* eslint-disable no-undef */ import React, { Component } from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' import { withRouter } from 'react-router-dom' import Explore from '../components/Explore' import { resetErrorMessage } from '../actions' class App extends Component { static propTypes = { // Injected by React Redux errorMessage: PropTypes.string, resetErrorMessage: PropTypes.func.isRequired, inputValue: PropTypes.string.isRequired, // Injected by React Router children: PropTypes.node } handleDismissClick = e => { this.props.resetErrorMessage() e.preventDefault() } handleChange = nextValue => { this.props.history.push(`/${nextValue}`) } renderErrorMessage() { const { errorMessage } = this.props if (!errorMessage) { return null } return ( <p style={{ backgroundColor: '#e99', padding: 10 }}> <b>{errorMessage}</b>{' '} <button onClick={this.handleDismissClick}>Dismiss</button> </p> ) } render() { const { children, inputValue } = this.props return ( <div> <Explore value={inputValue} onChange={this.handleChange} /> <hr /> {this.renderErrorMessage()} {children} </div> ) } } const mapStateToProps = (state, ownProps) => ({ errorMessage: state.errorMessage, inputValue: ownProps.location.pathname.substring(1) }) export default withRouter( connect(mapStateToProps, { resetErrorMessage })(App) )