React router
Dodajemy nowe widoki
import React from 'react';
import Container from '../Container/Container';
const Info = () => (
<Container>
<h2>Info</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</Container>
);
export default Info;
import Info from '../Info/Info';
import {BrowserRouter, Switch, Route} from 'react-router-dom';
Aktywne linki
<NavLink exact to='/' activeClassName='active'>Home</NavLink>
<NavLink exact to='/info' activeClassName='active'>Info</NavLink>
Przejścia pomiędzy widokami
import {AnimatedSwitch} from 'react-router-transition';
Zmiany w ListContainer
const mapStateToProps = (state, props) => {
const id = props.match.params.id;
const filteredLists = state.lists.filter(list => list.id == id);
const listParams = filteredLists[0] || {};
return {
...listParams,
columns: getColumnsForList(state, id),
};
};
const mapStateToProps = (state, props) => {
const id = props.match.params.id;
const filteredLists = state.lists.filter(list => list.id == id);
return {
columns: getColumnsForList(state, id),
};
};
Zadanie: Wyniki wyszukiwania
import React from 'react';
import styles from './Search.scss';
import Button from '../Button/Button';
import PropTypes from 'prop-types';
import Icon from '../Icon/Icon';
class Search extends React.Component {
state = {
value: '',
visibleButtons: false
}
handleChange(event){
this.setState({
value: event.target.value,
visibleButtons: event.target.value.length > 0,
});
}
handleOK(){
}
render() {
const {value} = this.state;
const {icon} = settings.search;
return (
<div className={styles.component}>
<input
type='text'
value={value}
onChange={event => this.handleChange(event)}
/>
<div className={styles.buttons}>
<Button onClick={this.handleOK}><Icon name={icon} /></Button>
</div>
</div>
);
}
}
export default Search;
this.props.history.push(`/search/${this.state.value}`);