简体   繁体   English

搜索栏未过滤本机反应的结果

[英]Search Bar is not filtering the result in react native

Here is the text input code...这是文本输入代码...

This is code is in SearchForm.js这是 SearchForm.js 中的代码

const SearchForm = ({ params, onParamChange }) => {
  return (
    <View style={styles.container}>
      <View>
        <Text>Description</Text>
        <TextInput
          onChange={onParamChange}
          value={params.description}
          style={styles.input}
        />
      </View>
      <View>
        <Text>Location</Text>
        <TextInput
          onChange={onParamChange}
          value={params.location}
          style={styles.input}
        />
      </View>
    </View>
  );
};

This code is in App.js此代码在 App.js 中

I am calling the Github job api in useFetchJobs我在 useFetchJobs 中调用 Github 作业 api

const { jobs, loading, error, hasNextPage } = useFetchJobs(params, page);
const [params, setParams] = useState({});
function handleParamChange(e) {
    const param = e.target.name;
    const value = e.target.value;
    setPage(1);
    setParams((prevParams) => {
      return { ...prevParams, [param]: value };
    });
  }
<SearchForm params={params} onParamChange={handleParamChange} />

Can you Please tell me why it is not working你能告诉我为什么它不起作用

Changed method and the way onChange is used.改变的方法和使用 onChange 的方式。 Try it out once.试一试。

<View>
            <Text>Description</Text>
            <TextInput
              onChange={(e) => onParamChange('description', e)}
              value={params.description}
              style={styles.input}
            />
          </View>
          <View>
            <Text>Location</Text>
            <TextInput
              onChange={(e) => onParamChange('location', e)}
              value={params.location}
              style={styles.input}
            />
          </View>

    function handleParamChange(param, e) {
        
        const value = e.target.value;
        setPage(1);
        setParams((prevParams) => {
          return { ...prevParams, [param]: value };
        });
      }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM