Skip to content

Wrapping TextInput and using another ref causing error #289

@juliscotto

Description

@juliscotto

I'm getting this error when I try to use the ref inside a wrapped TextInput:

TypeError: inputRef.current.clear is not a function. (In 'inputRef.current.clear()', 'inputRef.current.clear' is undefined)

My code:

const generateTestHook = useCavy(); const TestableTextInput = wrap(TextInput);

<TestableTextInput
        returnKeyType={"search"}
        returnKeyLabel={"search"}
        ref={generateTestHook("HomeScreen.SearchQuery", inputRef)}
        style={styles.input}
        maxLength={25}
        placeholder="¿Qué buscas?"
        placeholderTextColor={"#808080"}
        onChangeText={(text) => {
          setCurrentQuery(text);
          setOnSearch(true);
          setOnTextInput(true);
        }}
        onSubmitEditing={() => {
          if (currentQuery.replace(/\s/g, "").length) {
            setQuery(currentQuery);
          } else {
            setCurrentQuery("");
            setQuery("");
            setOnSearch(false);
          }
          setOnTextInput(false);
        }}
        value={currentQuery}
        onFocus={() => {
          setOnSearch(true);
          setOnTextInput(true);
          //sheetRef.current.snapTo(2);
        }}
        onBlur={() => {
          setOnTextInput(false);
        }}
 />

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions