It took me something like eight hours to understand how to bring Next.js 13 Beta to let a user put text into an input field and use that text in a function. Here’s why:
The component has to be client-side for a state driven input field to work.
The function had to be invoked server-side because it uses an (OpenAI) API key that would have otherwise been exposed.
I tried for hours to somehow manage to take the string from the input field and throw it into the server rendered component. That doesn’t even make any sense and was always going to fail. It would be a paradox.
It took me only a couple of hours to come to that conclusion. That’s when I figured that Route Handlers, formerly known as API Routes might be the solution. There was only one problem: I didn’t really understand what they are, what they’re doing and what exactly they’re meant to be used for. After playing around with them for a while, I somehow lost my mind and went back to my initial approach: Trying to convince a server side component to dynamically render something based on data from a client side component.
Well, what can I say. I did what I set out to do when I cancelled my Webflow powered book blog because of their insane pricing: I learned how to program and built my own. It’s a lot faster, has more features and doesn’t cost me anything.
You can play around with it here: buch.fyi I haven’t written any opinions for books read in 2022/23 but everything else should be there.
After talking to friends about how I don’t understand how a React application can securely use API keys and secret data like that, they pointed me in the general direction of Next.js and explained server side rendering to me. I worked through the documentation and built buch.fyi on top of it. Since I love life on the cutting edge, I’m using Next.js 13 with the new /app folder structure.
While doing so I discovered that I don’t need any API keys or databases at all. It’s all markdown files, baby!
It’s all TypeScript! Look at me, writing typed code. All type saved up in here.
I’m still using TailwindCSS for everything CSS related. It’s just fun to use, I’ll refresh my classic CSS knowledge when the time comes.
Some transitions are using Framer Motion, which is as complex as it’s amazing.