The library that saved the day: @therealwolf's recommendation
neoxian·@rufans·
0.000 HBDThe library that saved the day: @therealwolf's recommendation
Just as developers will always face bugs while developing, I've run into my fair share of them while revamping my portfolio website today.
Some time ago, I encountered a problem with the ```dhive ``` library with the Next.js framework. It caused my application to crash on production while it worked fine on development.
I checked the library’s GitLab to notice there has been an issue already partnering to why my app crashed. But I still commented on it. Unfortunately, for weeks, I didn’t get any reply.
luckily for me, I found another library to proceed with my development. To fix the known issues, I replaced the dhive with the hivejs library. At first, everything worked fine.
One of the first things I did was move the code base from being a component to being a page/route in my Next.js environment. This change allowed me to access my blog with the /blog route, making it easier for users to find and read my hive posts.
However, when I started to revamp my portfolio by creating a blog page/route, I ran into another issue.
---
#### The undefined Error
---
The hivejs library was returning undefined each time I tried to assign a variable and tried to fetch posts with the getdiscussionbyblog logic. This was a frustrating setback, as I wasn't sure how to proceed. The only solution that I could think of was to instantly set the data fetched inside a usestate hook. I tried it and it worked fine. I never knew I was going to face another issue.
I tried to run my app on production then I noticed that it’s not possible to use a hook on the page section of nextjs. This is because the route part of nextjs runs on the server before the app is rendered to the client.
Just when I was about to give up and try a different approach, I received a reply to the issue I had commented on weeks earlier. @therealwolf had referred me to another library, which I quickly installed and tested.
To my relief, everything worked perfectly with this new library. It was a much-needed solution to a problem that had been causing me a lot of frustration.😀
I removed all the hooks from the blog route, then assigned a variable to the getdiscussion logic from the new library. All of these were done using getServerSideProps.
```
export async function getServerSideProps() {
const client = new Client()
// Fetch data from external API
const posts = await client.database.getDiscussions('blog', { tag: 'rufans', limit: 10 })
// Pass data to the client-side
return {
props: {
posts,
},
}
}
```
---
#### What changed?
---
<center> fin.png)
</center>
I changed the display of my blog from a swipperjs to a list display. This not only made the blog look more organized and easier to read, but it also made it easier for users to navigate through the different posts since I increase the number of posts to be fetched on a request.
I also increased the number of posts that were fetched from 3 to 10. I did this by using the following code:
```
const posts = await client.database.getDiscussions('blog', { tag: 'rufans', limit: 10 })
```
In conclusion, this experience reminded me of how important it is to stay up-to-date with new tools and technologies and be open to trying different approaches when faced with challenges.
👍 poshtoken, josediccus, thaiteam, gloriaolar, quochuy, smartvote, hivetrending, hive.pizza, fieryfootprints, nata86, pizzabot, dajokawild, john9inch, trentonlundy1, jam728, thaddeusprime, banzafahra, cherute, lothbrox, chechostreet, masterfarmer, shauner, veryanprime, kingneptune, crypt0gnome, mystic.realms, drunksamurai, anikekirsten, fireguardian, dumnebari, ravenmus1c, nooblogger, kennysgaminglife, portsundries, goliathus, dadspardan, huzzah, mstamatov, cooperclub, creodas, wizzitywillican, dibblers.dabs, lucimorningstar, onewolfe, rentaw03, epicur0, marcinxyz, h3m4n7, spiritverve, stickupcash, thunderjack, zeclipse, blocktunes, gwajnberg, dalekma, incantia, hurtlocker, rondonsleezy, fefe99, marriot5464, funnel, cre47iv3, adamada, luciannagy, vokus, finris, szmobacsi, nane-qts, studio3141, jude.villarta, jazzhero, romeskie, sgbonus, bestofph, markjason, kendallron, pinas, nyxlabs, tdctunes, quentincc, blocktunesdao, sovstar, scholaris.stem, marynn, peerfinance, lemouth, steemstem-trig, steemstem, dna-replication, minnowbooster, howo, aboutcoolscience, robotics101, stemsocial, roelandp, curie, edb, metabs, walterjay, mobbs, helo, abigail-dantes, kenadis, intrepidphotos, geopolis, alexdory, melvin7, deholt, gerdtrudroepke, pboulet, crowdwitness, superuser3, valth, samminator, zeruxanime, waivio.curator, aidefr, r00sj3, pab.ink, laruche, noelyss, lamouthe, techslut, roguewriter, dhimmel, oluwatobiloba, jga, sustainablyyours, sam99, alexander.alexis, tsoldovieri, meno, postpromoter, sco, fragmentarion, francostem, ryenneleow, gadrian, de-stem, motherofalegend, stem.witness, apokruphos, prosocialise, gaottantacinque, zonguin, aaronleang, temitayo-pelumi, cribbio, bedazzled, gasaeightyfive, meritocracy, milagrosmhbl, spirit09, enzor, fineartnow, doctor-cog-diss, privex, iansart, brotherhood, kristall97, fsm-core, lowelonerf, axelx12, therising, mamalikh13, thesoundof, gohive, justyy, bloghound, cheese4ead, barizon, manic.calm, punchline, takowi, armandosodano, steemean, steemwizards, stayoutoftherz, dandesign86, yixn, ew-and-patterns, sorin.cristescu, eliana-art, rynos-6, raph1, mugueto2022, the-burn, princessmewmew, nateaguila, laviesm, bscrypto, djennyfloro, steemcryptosicko, wanderingmoon, conocorp, the-grandmaster, thecryptodrive, steveconnor, lis0426csm, reverio, bflanagin, zyx066, tanray, aries90, bitrocker2020, revo, thelittlebank, aabcent, dynamicrypto, kkndworld, cliffagreen, arunava, talentclub, drricksanchez, rocky1, hive-life, juancar347, qwerrie, netaterra, oscarina, minas-glory, tfeldman, technicalside, quentinvb, therealyme, monsterjamgold, cnfund, rt395, brianoflondon, federacion45, neneandy, podping, cloh76, detlev, neumannsalva, pandasquad, superlotto, aicu, quinnertronics, irgendwo, wrestorgonline, m0rt0nmattd, therealwolf, jfuji, djlethalskillz, diabonua, yoghurt, smartsteem, felt.buzz, sunsea, kylealex, marcocasario, apendix1994, hukepuk, xeldal, mcsvi, meanbees, ibt-survival, elevator09, forykw, sanderjansenart, primersion, celinavisaez, robibasa, martinthemass, mr-rent, adol, enki, hiddendragon, killerbot, carilinger, lordvader, grapthar, pladozero, atheistrepublic, dondido, jerrybanfield, juecoree, uche-nna, calatorulmiop, yjcps, mammasitta, aaronkroeblinger, realblockchain, acousticguitar, sardrt, massivevibration, dandays, bennettitalia, safrizal.mus, vaultec, nfttunz, eric-boucher, gaming.grants, robertbira, esthersanchez, imcore, dranren, flatman, orlandogonzalez, lartist-zen, holoferncro, hivebuzz, lizanomadsoul, feltoxxx, steemitboard, marivic10, fengchao, raphaelle, sbi5, more4less, yuslindwi, hundlola, hrhmikelength, elizabeth-22, ennydee, hjmarseille, abkevwe, eythorphoto, iumac03, hoboway, sodrill, mrstaf, slefesteem, tomatom, azmielbanjary, topworlds, bai123, mofobunny, thiskava, marsresident, joshglen, fatherfaith, kdee916, mhm-philippines, edward-abu, anna.kathaxrina, filosof103, eniola1990, poggersdude, perinator, kathryn95, riottales, starbooks, swirly, psyo, tajimkhan, netvalar, vankushfamily, genepoolcardlord, sixexgames, urchice, silasvogt, battebilly, tboyloyal, lancergrows, pearlumie, nwagod4, gnarlyanimations, dreamm, sholly1, oilprinzz, hardaeborla, montanacellist, nanggroe1, rent-an-ape, rencongland, airhawk-project, marvel1206, ataliba, ihsan19, makrotheblack, funshel, bookoons, mayib, juanhobos, casilokodesing, olujay, photohunter2, era131, randomblock1, steeminer4up, peterpanpan, justtryme90, daj, quduus1, colmedwardsphoto, kerry234, dawizy, onwugbenuvictor, suteru, thedrewshow, tomlee, joeyarnoldvn, cheesom, preciousimo, cynicalcake, jtm.support, supperbotsps.com, martinstomisin, shamzy, eustace-kidd, justfavour, enjoyy, netzisde, angoujkalis, predict-crypto, jsalvage, din0baba, chuxter, senseisar, simba, dashfit, kisom1, irisworld, mirfaner, jsynnthagr8, berkaytekinsen, burlarj, jenniferjulius, hungryanu, highhaschdi, cindynancy, atjehsteemit, airhawk-exchange, k-banti, dantommy, tomlee.sports, tezzmax, friesennerz, firstamendment, eprolific, jacksondavies, rachelleignacio, ihal0001, daniky, zackarie, kayntan, paololuffy91, ilovegames, zarnoex, emekasegun, motivatorjoshua, thomaskatan, yestermorrow, hyborian-strain, digitalmack, vonzeppelin, tochprince, nascimentoab, tolarnee, bcrafts, nascimentocb, blackmagic, akumar, parth7878, sunshinebear, carloniere, mrxplicit, kalivankush, gamersclassified, holovision.stem,