搜索栏未在react native中筛选结果



这是文本输入代码。。。

这是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>
);
};

此代码在App.js 中

我在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} />

你能告诉我为什么不起作用吗

更改了方法和onChange的使用方式。试一下。

<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 };
});
}

最新更新