Skip to content

Commit

Permalink
Merge pull request #32 from ercumentlacin/ercu
Browse files Browse the repository at this point in the history
Add .env file and change App.tsx file
  • Loading branch information
NisanurBulut authored Apr 27, 2021
2 parents df4fd1a + 2e08cef commit 40522e3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions SayHiStyledComponent/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_BASE_URL=https://v2.jokeapi.dev/joke/Any
1 change: 1 addition & 0 deletions SayHiStyledComponent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@types/react-dom": "^17.0.3",
"@types/styled-components": "^5.1.9",
"axios": "^0.21.1",
"dotenv": "^8.2.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-query": "^3.13.12",
Expand Down
9 changes: 7 additions & 2 deletions SayHiStyledComponent/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ import cat from "./images/cat.png";
import axios from "axios";
import { Joke } from "./types/Joke";

const BASE_URL = "https://v2.jokeapi.dev/joke/Any";

require('dotenv').config()

const App:React.FC=()=>{



const [search, setSearch] = useState("");
const [error, setError] = useState(false);
const [jokes, setJokes] = useState<Joke[]>([]);
Expand All @@ -26,7 +31,7 @@ const App:React.FC=()=>{

const getJokes = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
const ENDPOINT = `${BASE_URL}?contains=${search}&amount=10`;
const ENDPOINT = `${process.env.REACT_APP_BASE_URL}?contains=${search}&amount=10`;
const { data } = await axios.get(ENDPOINT);
if (data.error) {
setError(true);
Expand Down

0 comments on commit 40522e3

Please sign in to comment.