Last active
January 27, 2019 11:57
-
-
Save darksh3ll/e45e7d34a3bac16a2ba1623d890653f8 to your computer and use it in GitHub Desktop.
passage de props par navlink
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, {Component} from 'react'; | |
| import {NavLink, Link} from "react-router-dom"; | |
| import {InputGroup, InputGroupAddon, Input} from 'reactstrap'; | |
| import {ListGroup, ListGroupItem} from 'reactstrap'; | |
| import "./NavigationAll.css" | |
| import axios from "axios" | |
| class NavigationAll extends Component { | |
| state = { | |
| filter: "", | |
| allContact: [], | |
| contact: [] | |
| }; | |
| retrieveData = async () => { | |
| const url = "/contacts"; | |
| const data = await axios.get(`${url}`); | |
| this.setState({allContact: data.data.contact}) | |
| }; | |
| componentDidMount() { | |
| this.retrieveData(); | |
| } | |
| handleChange = (e) => { | |
| this.setState({[e.target.name]: e.target.value}) | |
| }; | |
| contact = (contact) => { | |
| this.setState({contact : contact}) | |
| } | |
| render() { | |
| return ( | |
| <div> | |
| <div className="nav"> | |
| <div> | |
| <InputGroup> | |
| <InputGroupAddon addonType="prepend">Search</InputGroupAddon> | |
| <Input placeholder="username" onChange={this.handleChange} name="filter" | |
| value={this.state.filter}/> | |
| </InputGroup> | |
| </div> | |
| <div className="icone"> | |
| <NavLink to="/contact"> | |
| <i className="fas fa-plus"></i> | |
| </NavLink> | |
| </div> | |
| </div> | |
| <div> | |
| { | |
| this.state.allContact.filter(contact => contact.firstname.includes(this.state.filter)) | |
| .map(contact => { | |
| return ( | |
| <ListGroup> | |
| <ListGroupItem className="box"> | |
| <div className="imgContact"> | |
| <img src="https://via.placeholder.com/100" alt=""/> | |
| </div> | |
| <div className="boxContent"> | |
| <div className="contentContact"> | |
| {contact.firstname} | |
| {contact.lastname} | |
| </div> | |
| </div> | |
| <div className="iconeArrow" onClick={() => this.contact(contact)}> | |
| <NavLink to={{pathname:"/details",state:{contact:contact}}}> | |
| <i className="fas fa-arrow-circle-right"></i> | |
| </NavLink> | |
| </div> | |
| </ListGroupItem> | |
| </ListGroup> | |
| ) | |
| }) | |
| } | |
| </div> | |
| </div> | |
| ); | |
| } | |
| } | |
| export default NavigationAll; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, {Component} from 'react'; | |
| import NavLink from "react-router-dom/es/NavLink"; | |
| import Info from "./Info"; | |
| class Display2 extends Component { | |
| state = { | |
| personne:[], | |
| }; | |
| object = (people) => { | |
| this.setState({personne:people}); | |
| console.log(people); | |
| }; | |
| render() { | |
| return ( | |
| <div> | |
| <div className="row"> | |
| {this.props.peoples | |
| .filter(people => people.name.includes(this.props.valeur)) | |
| .map((people, index) => ( | |
| <div className="card col-sm-3 d-flex justify-content-around" key={index}> | |
| <img className="card-img-top shadow-lg p-3 mb-5 bg-white rounded " | |
| width={250} | |
| height={400} | |
| src={people.image} | |
| alt="#" | |
| /> | |
| <div className="card-body"> | |
| <h5 className="card-title">{people.name}</h5> | |
| <NavLink | |
| exact to={{pathname:"/Info",state:{personne:people}}}> | |
| <a href="#" className="btn btn-dark" onClick={()=>this.object(people)}>Plus info</a> | |
| </NavLink> | |
| </div> | |
| </div> | |
| ))} | |
| </div> | |
| </div> | |
| ); | |
| } | |
| } | |
| export default Display2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment