![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@rickbrown/use-fetch
Advanced tools
A custom React hook to simplify the fetch API. This has been created as part of a blog post series. Part one can be seen here
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
To get this boilerplate running locally you will need:
npm install --save @rickbrown/use-fetch
import React from 'react'
import { useFetch } from '@rickbrown/use-fetch'
const App = () => {
const [response, error, isLoading] = useFetch(
`https://jsonplaceholder.typicode.com/users/5`
)
if (isLoading) {
// can be used for loading indicator/spinner etc.
return <h1>Loading..</h1>
}
if (error) {
// handle any error
console.log(error.message)
}
// if the code reaches this point, loading has been completed and there is no error
// you have been returned a `response` object
return (
<>
<pre>response: {JSON.stringify(response, null, 2)}</pre>
</>
)
}
export default App
response
object{
'end-point': String,
status: Number,
error: Boolean,
'data-type': String,
'data-length': Number,
data: Object
}
So, if you wanted to remove all the extra information, and you only want the data
object, and you are only using the use-fetch
hook once in your component, your API could look like this:
const [{ data }, error, isLoading] = useFetch(
`https://jsonplaceholder.typicode.com/users/5`
)
use-fetch
will also accept a conditional statement. I will give an example by checking the URL. In this example we only want to make the request for the forecastData
when the first fetch
call for weatherData
has been resolved. So we can use a ternary operator in the second fetch
call. If there is no weatherData
, we just return, and the hook does nothing. This conditional allows us to use our hook multiple times in the same component:
const [weatherData, weatherError, weatherIsLoading] = useFetch(
`http://api.openweathermap.org/data/2.5/weather?lat=${coords.lat}&lon=${coords.long}&APPID=${WEATHER_API_KEY}&units=metric`
)
const [forecastData, forecastError, forecastIsLoading] = useFetch(
weatherData.data
? `http://api.openweathermap.org/data/2.5/forecast/daily?id=${weatherData.data.id}&appid=${WEATHER_API_KEY}`
: null
)
Available scripts:
yarn test
yarn test:watch
yarn test:coverage
This project is licensed under the MIT License - see the LICENSE.md file for details
FAQs
A custom React hook to simplify the fetch API.
We found that @rickbrown/use-fetch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.