Skip to content

Commit 64afe19

Browse files
committed
feat(urlParam): update URL based on dropdown countries
1 parent 650e961 commit 64afe19

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/App.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState } from 'react';
2-
import { BrowserRouter as Router, useLocation } from "react-router-dom";
2+
import { BrowserRouter as Router, useLocation, useHistory } from "react-router-dom";
33

44
import Header from './Header/Header';
55
import Home from './Home/Home';
@@ -13,10 +13,16 @@ import './App.scss';
1313

1414
function App() {
1515
const location = useLocation();
16+
const history = useHistory();
1617

1718
const suggestedCountry = location.pathname.slice(1).toUpperCase();
1819
const country = countries.map(country => country.value).includes(suggestedCountry) ? suggestedCountry : 'CL';
19-
const [pais, handleSetPais] = useState(country);
20+
const [pais, setPais] = useState(country);
21+
22+
const handleSetPais = (country) => {
23+
setPais(country);
24+
history.push(`/${country.toLowerCase()}`);
25+
};
2026

2127
return (
2228
<AppContext.Provider value={{

0 commit comments

Comments
 (0)