-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render search results #28
Comments
I'm going to start working on some Queries next |
I started something here if you want to build off that: #30 |
So thinking this through, haven't had time to try implementing any of it, but the flow of data will be a little tricky/complicated. Step 1 (JS object)From the form page (the {
keywords: "react",
labels: ["good first issue", "help wanted"],
language: "JavaScript"
} These are the relevant bits of our state. Each of these fields could possibly be empty: Step 2 (query string)In any case, we'll want to take that JS object, and convert it to a valid query string, so the above would become: "keywords=react&labels[]=\"good first issue\"&labels[]=\"help wanted\"&language=JavaScript" (or something like that, there doesn't really seem to be a strict standard around how this gets formatted). That query string gets URI encoded and tagged on the end of the URL when we navigate to the Step 3 (back to JS object and to GraphQL query)The Steps 1 & 2 (serializing/deserializing between JS objects to query strings) is a solved problem, so I think we'd be fine going with the |
Cool. Yeah I'm definitely a little lost when it comes to our custom state management and how that all gets passed around. I've been spending some time going through the custom hooks tutorial on Level Up Tuts. It's helping as I look over it all again this morning but it's not all clicking yet. Everything you wrote above makes sense but I wouldn't know where to start wiring it all up. So I'm just going to keep plugging away and breaking down the pieces here until I can follow it all without getting lost |
No worries, I'll see if I can add some documentation on how to use the state management (I'm a little fuzzy on how I set it up myself). But from what I remember I don't think we'll really need to add any more state, though we will need to do the action creator/action/dispatch dance. A rough draft at hooking it all up without doing it in top level state would just be to do it in // in SearchForm.js
import { useSearch } from "App"; // This gives access to our context where state is stored
import { stringify } from "query-string";
import { navigate } from "@reach/router";
...
// This is a little weird looking, but it's how we have our state management set up.
// The hook returns search state as first element of array and a `dispatch` function
// as second element. Not using `dispatch` here so we're just grabbing what we need
// from first element.
const [{ keywords, selectedLabels, selectedLanguage }] = useSearch();
const handleSubmit = e => {
e.preventDefault();
const str = stringify({
keywords,
labels: selectedLabels,
language: selectedLanguage
});
navigate(`/results?${str}`); // Our state can now be read from the query string
}; Then inside of I haven't tested the above, but just sketching it out so you have a better idea of how state management is wired up. The more proper way to do it might be to create actions and dispatch them, but that action would need a reference to Edit: just realized I had a |
So after a very crazy and busy week I'm finally diving back in here. It's crazy how much I can forget in a week 😬 Anyway I just branched off to mess around with this and see if I could get it working but I'm running into this error: "ReferenceError: can't access lexical declaration `useSearch' before initialization" which after some googling seems to be a "circular dependency" issue but I'm not sure why I can't access useSearch in out SeachForm component. It all looks like its in order to me. It could have to do with a missing value prop in the SeachProvider, but I'm not totally sure. |
Edit: Actually, I think this line might be the problem:
This works for me if I move this down a few lines, so that it's inside the SearchForm component. Its a hook so it should be called inside the component, normally React gives better error messages about that so this was a bit strange. Let me know if there are further issues.
|
Of course! That makes sense thanks man. I'll keep plugging away and see how far I can get tonight. And no worries on the time. It's kinda nice to have something I can just chip away at. And that medium link was real helpful |
env
variablesThe text was updated successfully, but these errors were encountered: