Estoy siguiendo el ejemplo de búsqueda instantánea de reacción aquí: https://www.algolia.com/doc/guides/building-search-ui/going-further/routing-urls/react/
const createURL = state => `?${qs.stringify(state)}`;
const searchStateToUrl = searchState =>
searchState? createURL(searchState): '';
const urlToSearchState = ({ search }) => qs.parse(search.slice(1));
Y tengo dificultades para entender cómo funcionaría esto en el próximo js, porque ¿cómo puedo conectar la searchStateToUrl
función a mi próximo enrutador, ya que no acepto ningún accesorio en el próximo js?
export function App({ location, history }) {
const [searchState, setSearchState] = useState(urlToSearchState(location));
const debouncedSetStateRef = useRef(null);
function onSearchStateChange(updatedSearchState) {
clearTimeout(debouncedSetStateRef.current);
debouncedSetStateRef.current = setTimeout(() => {
history.push(searchStateToUrl(location, updatedSearchState));
}, DEBOUNCE_TIME);
setSearchState(updatedSearchState);
}
useEffect(() => {
setSearchState(urlToSearchState(location));
}, [location]);
Solución del problema
¿Viste este ejemplo de Vercel?
https://github.com/vercel/next.js/blob/canary/examples/with-algolia-react-instantsearch/pages/index.js
No hay comentarios:
Publicar un comentario