This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('testing error in request', async () => { | |
const mock = new MockAdapter(axios); | |
mock.onGet().reply(404, {data: []}); //or mock.onGet().networkError(); | |
const {result, waitForNextUpdate} = renderHook( | |
({url}) => useRemoteData({url}), | |
{ | |
initialProps: { | |
url: '', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('testing success get request', async () => { | |
const mock = new MockAdapter(axios); | |
mock.onGet().reply(200, {data: []}); | |
const {result, waitForNextUpdate} = renderHook( | |
({url}) => useRemoteData({url}), | |
{ | |
initialProps: { | |
url: '', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Testing uses cases for async hook', () => { | |
it('', async () => { | |
const mock = new MockAdapter(axios); | |
mock.onGet().reply(200, {data: []}); | |
const {result, waitForNextUpdate} = renderHook( | |
({url}) => useRemoteData({url}), | |
{ | |
initialProps: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
import MockAdapter from 'axios-mock-adapter'; | |
describe('Testing uses cases for async hook', () => { | |
it('testing success get request', async () => { | |
const mock = new MockAdapter(axios); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
//the keys has to be the same that in the .env file | |
API_URL: 'http://mock', | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//IMPORTS | |
interface ILogos { | |
light: string; | |
dark: string; | |
} | |
export interface HomeResponse { | |
id: string; | |
name: string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {useState, useEffect} from 'react'; | |
import axios, {AxiosError, AxiosRequestConfig} from 'axios'; | |
import Config from 'react-native-config'; //lib used for env vars | |
//set the base url for axios | |
axios.defaults.baseURL = Config.API_URL; | |
const useRemoteData = <T>({url, method, headers, data}: AxiosRequestConfig) => { | |
const [response, setResponse] = useState<T>(); | |
const [error, setError] = useState<AxiosError>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { | |
View, | |
} from 'react-native'; | |
import {useRemoteData} from 'hooks/useRemoteData'; //or '@hooks/useRemoteData' | |
import {Button} from 'components/button'; //or '@components/button' | |
const Home: React.FC = () => { | |
return ( | |
<View > |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins: [ | |
[ | |
'module-resolver', | |
{ | |
root: ['./src'], | |
extensions: ['.ios.js', '.android.js', '.js', '.ts', '.tsx', '.json'], | |
alias: { | |
'@components': './src/components', | |
'@hooks': './src/hooks/', | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"baseUrl": ".", | |
"paths": { | |
"*": ["src/*"], | |
"@components/*": ["src/components/*"], | |
"@hooks/*": ["src/hooks/*"], | |
}, |
NewerOlder