Skip to content
Snippets Groups Projects
Commit b3172e94 authored by Andrej Rasevic's avatar Andrej Rasevic
Browse files

adding exercise 4

parent d07666ea
No related branches found
No related tags found
No related merge requests found
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Exercise 4: React Search/Filter application
## Due Date: Friday January 21st, 2021 11:59 PM
## Objectives: To become aquainted with React components, state, and JSX, practice array functions (filter, map, reduce, etc..)
## Specifications/Requirements
We have provided you with a complete React application bootstrapped with the react cli tool. To complete this project you need to create 2 components: List and Search.
The Search component will display a text input box that will allow the user to enter a city or state. As the user enters data the application will display a live list of results that match the current text in the input field. We have provided you with the fetch request inside of the componentDidMount lifecycle method in `Search.js`. Do not change or add any code to this method. You are responsible for taking the results from this request to check against the results from the fetch request.
Hint: you will need to define a handler to respond to an onChange event triggered inside of the input box. Additionally, once you retrieve it's value you will want to check to see if it matches the results from the fetch request using a regular expression. Here is a reference to regular expressions in javascript as well as an online tester:
https://www.w3schools.com/jsref/jsref_obj_regexp.asp
https://regex101.com/
Once you have stored the matched data you will then pass them to the List component.
In List.js you will create the component that will create an unordered list and display each matched item inside of it.
Note: React requires entries in an unordered list to contain a "key" property that must be unique. For more information on lists and keys in React, read over the official documentation:
https://reactjs.org/docs/lists-and-keys.html
Hint: the List component will be receiving the collection of matched data as a prop. Additionally, for each list item the component will display the data in the following format: ```<city> - <state>```. To know how to retrieve those values from the request object, inspect the JSON object in the console.
__Note: In order to run the application run ```npm install``` and then ```npm start``` in the top level directory of the exercise and open a browser and navigate to localhost:3000 in order to see your application running. You can copy paste the endpoint to see the JSON objects__
\ No newline at end of file
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.<br>
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.<br>
You will also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.<br>
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.<br>
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.<br>
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
### Analyzing the Bundle Size
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
### Making a Progressive Web App
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
### Advanced Configuration
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
### Deployment
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
### `npm run build` fails to minify
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
This diff is collapsed.
{
"name": "exercise4",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Project 2</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
import React from "react";
import Search from "./components/Search";
function App() {
return <Search />;
}
export default App;
import React, { Component } from "react";
class List extends Component {
}
import React, { Component } from "react";
class Search extends Component {
/* DO NOT MODIFY */
componentDidMount() {
const allPlaces = [];
const endpoint =
"https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json";
fetch(endpoint)
.then(data => data.json())
.then(results => {
allPlaces.push(...results)
this.setState({ places: allPlaces })
})
.catch(error => console.log(error));
}
}
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
ReactDOM.render(<App />, document.getElementById("root"));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment