Giter VIP home page Giter VIP logo

world-wise-app's Introduction

WORLD WISE APP WITH REACT ROUTER

DESCRIPTION

  • This is a simple app that users can add their visiting cities and countries to the list. Also, they can delete the cities and countries from the list. This app is created with related to the React Ultimate Course by Jonas Schmedtmann.

FEATURES

  • Search through Map and Get the City Details
  • Add City to the List
  • Delete City from the List
  • Login and Logout
  • Geo Location

SCREENSHOTS

Home Page Cities Page Form Page Login Page

WHAT I LEARNED

REDUCER METHOD

  • The reducer method is a built-in JavaScript function that is used to reduce an array to a single value.

  • It takes two arguments: an accumulator and a current value.

    • The accumulator is the value that is returned after each iteration.
    • The current value is the value of the current element in the array.
  • The reducer method is commonly used with the reduce() function to perform operations on arrays.

Here's an example of a reducer method that takes an array of objects and returns a new array with only one object per unique country:

const countries = cities.reduce((accumulator, currentvalue) => {
  if (!accumulator.map((item) => item.country).includes(currentvalue.country)) {
    return [...accumulator, currentvalue];
  }
  return accumulator;
}, []);
  • In this example, the reduce() function is used to iterate over the cities array and accumulate the unique countries into the countries array.
  • The map() function is used to extract the country property from each object in the accumulator array and check if it includes the country property of the currentvalue object.
  • If it does not include the country property, the currentvalue object is added to the accumulator array.

REACT ROUTER

  • React Router is a collection of navigational components that compose declaratively with your application.
  • You can install it using npm install react-router-dom.

use <NavLink> instead of <Link>

  • <NavLink> is a special version of the <Link> that will add styling attributes to the rendered element when it matches the current URL.
  • For example, if current URL is /about, then the element will receive the active class name.
  • We can select that using CSS (pseudo class) and style it however we want.

rested routing

  • Actually, it is very easy to implement rested routing. All we need to add related nested routes wrapped around parent route.
<Route path='app' element={<AppLayout />}>
  <Route index element={<p>Dashboard</p>} />
  <Route path='cities' element={<p>List of cities</p>} />
  <Route path='countries' element={<p>List of countries</p>} />
  <Route path='form' element={<p>Form</p>} />
</Route>
  • index element is the default route. It will be rendered when the parent route is rendered.
  • Now, Where these routes will be rendered? We need to add <Outlet /> in the relavant component.

USEPARAMS HOOK

  • The useParams hook allows us to access the params from the current route.
const { id } = useParams();

USESEARCHPARAMS HOOK

  • The useSearchParams hook allows us to access the query string from the current route.
const [searchParams, setSearchParams] = useSearchParams();
  • How to get the value of a specific query string?
www.example.com/app/cities/lisbon?lat=38.7223&lng=-9.1393
const lat = searchParams.get("lat");
const lng = searchParams.get("lng");
  • How to update the value of a specific query string?
setSearchParams({ lat: 38.7223, lng: -9.1393 });

USENAVIGATE HOOK

  • The useNavigate hook allows us to navigate to a different route.
const navigate = useNavigate();

const handleClick = () => {
  navigate("/app/form");
};

Navigate FUNCTION

  • This is not comonly used. But there are some cases where we need to use this function. Also, when we can't use hooks, we can use this function.
<Route index element={<Navigate replace to='cities' />} />
  • replace prop will replace the current route with the new route. This will enable us to go back to the previous route using the browser back button.

URL FOR STATE MANAGEMENT

  • Easy way to store state in a global place, accessible to all components in the app.

  • Good way to pass data from one page into the next page.

  • Makes it possible to bookmark or share the page with the exact UI state it had at the time.

PARAMS AND QUERY STRING

www.example.com/app/cities/lisbon?lat=38.7223&lng=-9.1393
``

GETTING CITY DETAILS FROM THE API

  • In order to get the city details from the API. We have used
https://api.bigdatacloud.net/data/reverse-geocode-client?latitude=0&longitude=0

world-wise-app's People

Contributors

kingmalitha avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.