Andtogetstartedonthelefthandside, I havevisualstudiocodeopen, andall I didwasrun N p x, createreactatwith a periodandthisgeneratedallofthebowleremployeesreactcodethatwe'regoingtoneed.
I thenwentaroundandremovedallthefiles.
Wedon't needsuch a CSSfilesandsuch a CZserviceworkersandtestfiles.
Butwithreactandhooks, it's a loteasiertobreakoutourlogicinto a customhook.
Sowe'regonnacreate a customhookcalledtheUseBooksearchdotJs.
Andinsideofherewe'regonnacreate a functionalcomponent.
Andifyouhavetheextensioninstalled, whichiscalled S sevenReactReduxgraphic, you'llglobalbosssnippetsyoucouldjusttype R F C andhitenter, andit'llgeneratealltheboilerplatecodeforyoufor a functioncomponentinreact, whichisalsothesameboilerplatecodeforactuallygenerating a customhook.
Soeverycharacterthatwetypeisactuallysendingoff a requestbecauseeverycharacterretypedcausesthisfunctiontorunwhichstatesarequery, whichthenupdatesoursearch.
Sowe'regonnafixthatin a littlebit.
Butwhat I dowanttolookatistheactualresults.
Wegetreturned.
Asyoucansee, thisdatahas a doc's field, whichisallofthedifferentbooksthatwerequerying.
Youcanseeit's a verylonglist, andinsideherewealsohavethenumberofresultsfoundaswellasthestart.
Sothisiswhatpagewe'recurrentlyon.
So, forexample, startzero, it's pageone, andthenwhateverourpaginationnumberis, whichinthiscase I thinkis 100.
Soin a usedbooksearchhere, Axioshas a reallyeasywaytosetupcancellations.
Ittakes a parametercalledcanceltoken, andthiscanceltokenisequaltoAxioslips.
Axios, Doc, canceltoken.
Andwewanttocreate a newoneofthese.
Thisisactuallycapitalcancelhereandinsideofthiscanceltoken, it's justgoingtotake a functionanddysfunctiontakes a singleparameter, whichisgoingtobethecanceltoken.
Essentially, thisisallowingustocancelourrequestandwhatwecandoinsideofuseeffectisifyoureturnsomethingfromuseeffect, youreturn a function, andtheninsidethatfunction, wecouldjustcallcancel, andthisisgoingtocancel a requesteverysingletime.
Doc's thisisgoingtobeourbooksandwewant a mapoverthatbecausewejustwantthetitleofourbooks.
Sowe'regonnahave a bookhere.
Wejustwanttoget b dottitlebecausethisisthetitleofourbookandwedon't careaboutanythingelseOnethingtonote, though, isthatthisactuallyisgoingtoreturntous a listofvariableswherewecouldhavemultipletitles, becausethisdataactuallydoesthingsbeyondjustthetitleofthebookandactuallyhasadditionsandotherthings.
Andthisfunctionisjustgoingtoprintout a divsowecanjustsayreturndiv.
Weneedtogiveit a keybecauseinreact, whenyoueveryourender a listofitemsfromanarray, youneed a uniquekey, which, inourcase, we'regonnaputourbookintherebecausethesearethetitlesofourbookon.
And a refisessentially a valuethatpersistaftereachrenderbecauseinsideofwrecked, everysinglethingthatwedoisonLeestoredinsidethatrenderunlessit's partofourstate.
Forexample, ifwewanttoget a referencetoourbookselementorinputelement, orifyouwanttoget a referencetosomethingthat's relatedtothedocument a p I andinourcasewe'reusingintersectionofServer, whichispartofthedocument a p I.
Sowe'regonnauseisusecallbackandthisactuallyhas a reallyuniqueinteractionwithuseref, whereifweset a ref, forexample, ifwesaidrefisequaltoandweused a userefSoif I justcomeuphereandsayconstlastbookelement, refand I saiditequaltousecallbackand I actuallysuppliedinformationhere, wecouldsetthatreferencedownhereandnowwhat's gonnahappeniswheneverthiselementiscreated, it's goingtocallthefunctioninsideofuse.
Thenextthingweneedtodoissetourcurrentobserversowecansayobserverdotcurrentisgoingtobeequalto a newintersectionobserver, andthisisgoingtotakein a functionanddysfunctiontakesalltheentriesthatareavailable.
Soeverythingthatit's watchingisgoingtobeinthisentriesarrayassoonastheybecomevisible, we'regonnaimplementthisfunctionandjust a littlebit.
Butwewanttofinishoutourfunctionherebysaying, ifwehave a node.
So, forexample, ifsomethingisactuallyourlastelement, wejustwanttomakesurethatourobserverisobservingit.