在Helper类函数的主组件上收集数据,返回React Native中的值

6mzjoqzu  于 2022-11-25  发布在  React
关注(0)|答案(1)|浏览(91)

我已经做了一个帮助类,包含了很多函数要从不同的组件调用,但我不能在主组件上得到返回值,从那里得到调用帮助函数?请帮助..

helper1: function(){
     console.log("ok Pressed");
    },
    checkIfRoomExist: function(param1, param2){
        console.log("userid", param2);
          firestore()
            .collection('userlist')
            .doc(param2)
            .get()
            .then(documentSnapshot => {
                console.log("room_id=>", documentSnapshot.data().room_id)
            })
            
    },
    helper3: function(param1, param2){

    }
}

export default helpers; `
 This is my helper class and i call it from my components and like
`import helper from './helper';`
Then Call the function and pass params like
`onPress={() => helper.checkIfRoomExist(param1, param2)}`
and now here i want the result of the checkIfRoomExist() function , how ?
lf5gs5x2

lf5gs5x21#

这是功能组件示例,

helper1: function(){
     console.log("ok Pressed");
return "some_data"
    }

    checkIfRoomExist: function(param1, param2){
        console.log("userid", param2);
          firestore()
            .collection('userlist')
            .doc(param2)
            .get()
            .then(documentSnapshot => {
                console.log("room_id=>", documentSnapshot.data().room_id)
            })
            
    }
    helper3: function(param1, param2){

    }

// this is how you can export multiple function from a compoenent
export {helper1,checkIfRoomExist,helper3}

// This is my helper class and i call it from my components and like
import {helper1,checkIfRoomExist,helper3} from './helper';

onPress={async () => let my_return_data = await helper1()}
onPress={() => checkIfRoomExist(param1, param2)}
onPress={() => helper3(param1,parami2)}

//类别元件范例

class helper {

   helper1: function(){
     console.log("ok Pressed");
    }

    checkIfRoomExist: function(param1, param2){
        console.log("userid", param2);
          firestore()
            .collection('userlist')
            .doc(param2)
            .get()
            .then(documentSnapshot => {
                console.log("room_id=>", documentSnapshot.data().room_id)
            })
            
    }
    helper3: function(param1, param2){

    }

}
// this is how you can export multiple function from a compoenent
export default helper

// This is my helper class and i call it from my components and like
import helper from './helper';

 
onPress={() => new helper().helper1()}
onPress={() => new helper().checkIfRoomExist(param1, param2)}
onPress={() => new helper().helper3(param1,parami2)}

相关问题