The new Form Component from Next.js 15

October 28, 20242 min read
The new Form Component from Next.js 15

Next.js 15 has just released and it has come with a new Form Component. This new Form Component is especially useful for forms that redirect to a new url for example when you try to search for blog posts and that redirects to a page that displays all the blog posts with that specific query.

How does it look

You can start using the new Form Component with Next.js 15. If we take my example that I just mentioned it would look something along the lines of this:

As you can see the input has a name of query this will be appended when you click the submit button to the URL. If you would press the submit button this would like like: /search/query="search string typed"

Benefits

As you can imagine this will have some additional benefits rather than using the default native form element. A benefit will be that Next.js will preload/prefetch the layout.ts and loading.ts files.

Another benefit is that the navigation will happen partially. This means that the client state will be kept and that the shared UI will stay in place, which will result in better performance for your website and ultimately a better user experience for your users.

Additional parameters

As we have touched the default Form component and its properties there are still some additional options you can provide the following properties:

  • action: The url or path that the form needs to navigate towards. An empty "" will submit the form and update the current path with the search parameters
  • replace: Replaces the current history state rather than pushing a new one
  • scroll: Controls the scrolling behaviour, the default will make it scroll to the top of the page
  • prefetch: Determines if the path should be prefetched or not

Conclusion

This new form component will be a joy to use and will make sure submissions that rely on a navigational component are handled correctly and as user friendly as possible. All in all it has its use cases and will not be used for all forms but it sure is a nice addition to this new Next.js Release.

Read more posts

Astro 3.0 has made waves in the web development community

Astro 3.0 has made waves in the web development community

September 10, 20245 min read
Astro 3.0 has made waves in the web development community as the first major framework to support the View Transitions API. This groundbreaking feature allows for seamless and visually appealing transitions between different states or views in web applications. With just a few lines of code, developers can easily incorporate fade, slide, morph, and persist animations across page navigation, creating a more immersive user experience.
Testing Next.js Apps: Best Practices & Tools

Testing Next.js Apps: Best Practices & Tools

August 15, 20247 min read
Testing is an essential part of the software development process, ensuring that applications function as expected and remain stable over time. In this blog, we will explore the best practices for testing Next.js applications using popular testing tools like Jest, Cypress, Playwright, and React Testing Library. By following these guidelines, you can maximize your confidence in your code, catch bugs early, and deliver high-quality software to your users.
React Compiler: what does it do and what's new

React Compiler: what does it do and what's new

June 9, 20243 min read
The React Compiler is a experimental compiler that has been open sources to the community in order to receive feedback and ideas. As you can imagine this means it is not production ready yet. However, it is a great way to get a feel for what this compiler of React does and can do. Keep in mind that this experimental compiler needs React 19 to work.
Refactoring ContentLayer to Velite

Refactoring ContentLayer to Velite

June 3, 20245 min read
As you might have heard already contentlayer is in a bit of a pickle with the amount of support the project is getting, you can read more about it