Onward to Data Submission
Thus far, you've learned a lot about data fetching. But as mentioned earlier in this chapter, React Router also helps with data submission.
Consider the following example component:
function NewPost() { return ( <form id="post-form"> <p> <label htmlFor="title">Title</label> <input type="text" id="title" name="title" /> </p> <p> <label htmlFor="text">Text</label> <textarea id="text" name="text" rows={3} /> </p> <button>Save Post</button> </form> ); } export default NewPost;
This component renders a <form>
element that allows users to enter the details for a new post. Due to the following route configuration, the component is displayed whenever the /posts/new
route becomes active:
const router = createBrowserRouter...