2
I have a database in Mongo with customers and establishments.
I want to recover the establishments filtered by category. My code is like this:
const [datas, setDatas] = useState([]) //recupera os dados
const [category, setCategory] = useState('tecnologias') //recupera a categoria selecionada
async function loadDatas(){
await api.get('/user/read/establishment', {params:{category: category}})
}
.
.
.
{datas.map(d =>(
<View style={styles.view}>
<TouchableOpacity onPress={()=>navigation.navigate('Establishment')}>
< Card title={d.nameEstablishment} time={d.sunday} chave={d._id}/>
</TouchableOpacity>
</View>
))
}
in params:{category:category}
the first Category is metadata from the database establishment table and the second, is what I get from React-Native with a tap on the screen.
It doesn’t work in the app, but in India it does, as much as I’ve seen this example on the official website. I am creating a gambiarra and doing several routes, but it is impractical, because it will have a time when the products will be shown by category and this will not be static, but dynamic (each establishment with its own).
Thank you for your answer, your way is correct, it works for me. The problem is that my mistake was not the time to read the data in the frontend, but in my database in the backend. Instead of ordering for 'params', I was ordering for 'body'.
– Joseph Isaac
kkkk thanks and good, managed to solve alone.
– Serginho junio