You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems like certain websites or elements don't return anything?
This worked:
const [isLoading, setLoading] = useState(true);
const [data, setData] = useState("");
useEffect(() => {
fetch('https://en.wikipedia.org/wiki/Nirvana_(band)')
.then(response => response.text())
.then(result => new JSSoup(result, false))
.then(f=>(f.findAll('span','mw-headline')[1]))
.then((t => t.getText()))
.then(f => setData(f))
.catch(function(error) {
setData('There has been a problem with your fetch operation: ' + error.message);
// ADD THIS THROW error
throw error;
}).finally(() => setLoading(false));
},[])
return(
<Text>{data}</Text>
)
But this did NOT work:
const [isLoading, setLoading] = useState(true);
const [data, setData] = useState("");
useEffect(() => {
fetch('https://www.google.com/search?q=sony')
.then(response => response.text())
.then(result => new JSSoup(result, false))
.then(f=>(f.findAll('h2', 'LC20lb MBeuO DKV0Md')[1]))
.then((t => t.getText()))
.then(f => setData(f))
.catch(function(error) {
setData('There has been a problem with your fetch operation: ' + error.message);
// ADD THIS THROW error
throw error;
}).finally(() => setLoading(false));
},[])
return(
<Text>{data}</Text>
)
I received a "[Unhandled promise rejection: TypeError: undefined is not an object (evaluating 't.getText')]" error for the 2nd code example.
Why is this the case?
The text was updated successfully, but these errors were encountered:
It seems like certain websites or elements don't return anything?
This worked:
But this did NOT work:
I received a "[Unhandled promise rejection: TypeError: undefined is not an object (evaluating 't.getText')]" error for the 2nd code example.
Why is this the case?
The text was updated successfully, but these errors were encountered: