I am developing a project with React Native which uses TypeScript. And coming from React.js, I noticed I am not able to put JavaScript within the HTML. Is there a way I can use the following code within .jsx HTML?
import * as React from 'react';import { StyleSheet, TextInput } from 'react-native';import { Text, View } from '../components/Themed';export default function SearchScreen() { const [searchText, setSearchText] = React.useState(''); const [searchData, setSearchData] = React.useState([]); React.useEffect(() => { if (searchText !== "") { fetch(`https://morning-star.p.rapidapi.com/market/v2/auto-complete?q=${searchText}`, {"method": "GET","headers": {"x-rapidapi-key": "sensitivedata","x-rapidapi-host": "morning-star.p.rapidapi.com" } }) .then(function(response) { return response.json(); }).then(function(data) { console.log(data.results); setSearchData(data.results); }); } }, [searchText]); return (<View style={styles.container}><TextInput style={{ height: 40, borderColor: 'gray', borderWidth: 1 }} onChangeText={text => setSearchText(text)} value={searchText} /> { searchData.map((stock, index) => (<Text key={index}>{stock.symbol}</Text> ) }</View> );}
I am basically attempting to display data from an API, save it in a state, and display it by mapping it. Is there a specific way you are supposed to display data/map it from within this component?