Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
388 views
in Technique[技术] by (71.8m points)

javascript - React Navigation only uses prev route param at HTTP request

I'm making a WAP using Expo web and React Navigation, yesterday I found a problem at my navigation flow and I do not found a fix.

I'm using react-navigation, I'm trying go to route with params and call a back-end method for HTTP request, this apparently works but only one time, the param in route change correctly in the browser but the HTTP request take only prev value at route (this does not a problem with my back-end method, I'm trying at postman and works), apparently react navigation does not refresh my params but I can see correctly param in my web-browser.

I to route using this:

 <TouchableOpacity
   onPress={
     ()=>{
       if (mShips.historials !== false) {
         navigation.navigate('HistorialMantenimiento', {id: 0,          equipoid: mShips.equipoid})    
         }
       }
     }
   > 
   <FontAwesome5
     name="history"
     size={18}
     style={styles.icon}
   />
</TouchableOpacity>

And I'm calling this at another component using "useEffect":

  useEffect(() => {
    const unsubscribe = navigation.addListener('focus', () => {
      if (id == 0) {
        letsGoTeam()
      }else{
        start()
      }
    });
    return unsubscribe;
  }, [navigation]);

And my "useEffect" calls this method:

const letsGoTeam = async()=>{
    console.log(equipoid)
    const token = JSON.parse(localStorage.getItem('user-token'));
    const getTareasbyequipo =  await axios.get(baseurl+'v2/historialdeequipo/'+equipoid, 
    {headers: { Authorization: `Bearer ${token.token}` }})
    .then(response =>{
      return response.data.data
    }).catch(error =>{
      alert(error.response.data.message)
      return null
    })
    console.log(getTareasbyequipo)
    if (getTareasbyequipo !== null) {
      setHistorial(getTareasbyequipo);
    }

  }

This code only works one time, then only takes the prev route at the function.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...