Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6213

How to pass multiple mobx observer states into function as parameter

$
0
0

I have these states:

  @observable questionString: string = '';  @observable questionLengthRemaining: number = 25;  @observable descriptionString: string = '';  @observable descriptionLengthRemaining: number = 500;

And i have this function:

onInputChamge = (state: any, stateLengthRemaining: any, maxLength: any, text: string) => {    state = text;    stateLengthRemaining = maxLength - text.length;  }

And here is my component:

<TextInput            multiline={true}            maxLength={questionMaxLength}            placeholder='Type your question here'            style={styles.questionInput}            onChangeText={(question) => this.onInputChamge(this.questionString, this.questionLengthRemaining, questionMaxLength, question)}          />

I have multiple textInputs that just need to do the same thing and take in the onInputChange function, but with just different states and lengths. For some reason, passing in the states as parameters in the function does not work, but when I create different functions for each of them like:

onQuestionChange = (text: string) => {    this.questionString = text;    this.questionLengthRemaining = maxQuestionLength - text.length;  }

It works.

It's super pointless to make the same function for each input, because that's what functions are supposed to limit. I'm using typescript and mobx by the way. Any way to do this? (If i console log the length remaining, it prints out correct numbers and strings so idk what is going on)


Viewing all articles
Browse latest Browse all 6213

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>