i'm getting this data from backend api. How can i add filter into json data? For Example if user want keywords which has search volume more than 20000. how can i do that? i appreciate your help in advance
2 Answers
Great question.
When gathering data from a backend api, in react here's how you would do it:
const [fetchedData, setFetchedData] = React.useState(null);
function fetchData() {
fetch('http://example.com/movies.json')
.then(response => response.json())
.then(data => setFetchedData(data));
};
// loads data initially on page load
React.useEffect(() => {
fetchData()
}, [])
//use this function to tie to an "onChange" or "onClick" event when submitting the values.
function filterData(inputValue) {
if(inputValue === "") return;
const filteredData = fetchedData.filter((value) => {
return value.SEARCH_INDEX_VALUE_HERE >= inputValue
}
return filteredData;
}
You can find a good description from here
This is given that the data returned is an array of objects, and the the SEARCH_INDEX_VALUE_HERE is whatever column key that is provided to the data you're filtering. In your case, it would be the "Search value" field I believe.
i'm getting this datawhat data (JSON)? There's only an image of the rendered view. Also, what have you tried to filter it? Have you tried.filter()?