Skip to content

Commit

Permalink
Remove api url from slices
Browse files Browse the repository at this point in the history
  • Loading branch information
Kidd254 committed Feb 29, 2024
1 parent 3906c61 commit 6173d1f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/redux/Details/detailsSlice.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
import axios from 'axios';

const baseUrl = process.env.REACT_APP_API_BASE_URL;
export const fetchDetails = createAsyncThunk(
'details/fetchDetails',
async (id, thunkApi) => {
try {
const baseUrl = `https://rickandmortyapi.com/api/character/${id}`;
const response = await axios.get(baseUrl);
const response = await axios.get(`${baseUrl}/character/${id}`);
return response.data;
} catch (error) {
return thunkApi.rejectWithValue(error.message);
Expand Down
4 changes: 2 additions & 2 deletions src/redux/characters/charactersSlice.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
import axios from 'axios';

const baseUrl = 'https://rickandmortyapi.com/api/characters';
const baseUrl = process.env.REACT_APP_API_BASE_URL;
export const fetchCharacters = createAsyncThunk(
'characters/fetchCharacters',
async (thunkApi) => {
try {
const response = await axios.get(baseUrl);
const response = await axios.get(`${baseUrl}/character`);
return response.data;
} catch (error) {
return thunkApi.rejectWithValue(error.message);
Expand Down
4 changes: 2 additions & 2 deletions src/redux/episodes/episodesSlice.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
import axios from 'axios';

const baseUrl = 'https://rickandmortyapi.com/api/episode';
const baseUrl = process.env.REACT_APP_API_URL;
export const fetchEpisodes = createAsyncThunk(
'episodes/fetchEpisodes',
async (thunkApi) => {
try {
const response = await axios.get(baseUrl);
const response = await axios.get(`${baseUrl}/episode`);
return response.data.results;
} catch (error) {
return thunkApi.rejectWithValue(error.message);
Expand Down
4 changes: 2 additions & 2 deletions src/redux/list/listSlice.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
import axios from 'axios';

const baseUrl = 'https://rickandmortyapi.com/api/location/';
const baseUrl = process.env.REACT_APP_API_BASE_URL;

export const getLocation = createAsyncThunk(
'list/getLocation',
async (thunkApi) => {
try {
const response = await axios.get(baseUrl);
const response = await axios.get(`${baseUrl}/location`);
return response.data.results;
} catch (error) {
return thunkApi.rejectWithValue(error.message);
Expand Down

0 comments on commit 6173d1f

Please sign in to comment.