Next.js Discord

Discord Forum

couldn't solve this error :/

Answered
Asian swamp eel posted this in #help-forum
Open in Discord
Asian swamp eelOP
can anyone help me why iam getting error ?
"use client";
import ImagePicker from "@/components/meals/image-picker";
import classes from "./page.module.css";
import { shareMeal } from "@/lib/actions";
import MealFormSubmit from "@/components/meals/meal-form-submit";
import useFormState from "react-dom";
export default function ShareMealPage() {
  const [state, formAction] = useFormState(shareMeal, { meassage: null });
  return (
    <>
      <header className={classes.header}>
        <h1>
          Share your <span className={classes.highlight}>favorite meal</span>
        </h1>
        <p>Or any other meal you feel needs sharing!</p>
      </header>
      <main className={classes.main}>
        <form className={classes.form} action={formAction}>
          <div className={classes.row}>
            <p>
              <label htmlFor="name">Your name</label>
              <input type="text" id="name" name="name" required />
            </p>
            <p>
              <label htmlFor="email">Your email</label>
              <input type="email" id="email" name="email" required />
            </p>
          </div>
          <p>
            <label htmlFor="title">Title</label>
            <input type="text" id="title" name="title" required />
          </p>
          <p>
            <label htmlFor="summary">Short Summary</label>
            <input type="text" id="summary" name="summary" required />
          </p>
          <p>
            <label htmlFor="instructions">Instructions</label>
            <textarea
              id="instructions"
              name="instructions"
              rows="10"
              required
            ></textarea>
          </p>
          <ImagePicker label="Your Image" name="image" />
          {state.message && <p className={classes.error}>{state.message}</p>}
          <p className={classes.actions}>
            <MealFormSubmit />
          </p>
        </form>
      </main>
    </>
  );
}
Answered by joulev
incorrect:
import useFormState from "react-dom";

correct (nextjs 14):
import { useFormState } from "react-dom";
View full answer

4 Replies

@Asian swamp eel can anyone help me why iam getting error ? js "use client"; import ImagePicker from "@/components/meals/image-picker"; import classes from "./page.module.css"; import { shareMeal } from "@/lib/actions"; import MealFormSubmit from "@/components/meals/meal-form-submit"; import useFormState from "react-dom"; export default function ShareMealPage() { const [state, formAction] = useFormState(shareMeal, { meassage: null }); return ( <> <header className={classes.header}> <h1> Share your <span className={classes.highlight}>favorite meal</span> </h1> <p>Or any other meal you feel needs sharing!</p> </header> <main className={classes.main}> <form className={classes.form} action={formAction}> <div className={classes.row}> <p> <label htmlFor="name">Your name</label> <input type="text" id="name" name="name" required /> </p> <p> <label htmlFor="email">Your email</label> <input type="email" id="email" name="email" required /> </p> </div> <p> <label htmlFor="title">Title</label> <input type="text" id="title" name="title" required /> </p> <p> <label htmlFor="summary">Short Summary</label> <input type="text" id="summary" name="summary" required /> </p> <p> <label htmlFor="instructions">Instructions</label> <textarea id="instructions" name="instructions" rows="10" required ></textarea> </p> <ImagePicker label="Your Image" name="image" /> {state.message && <p className={classes.error}>{state.message}</p>} <p className={classes.actions}> <MealFormSubmit /> </p> </form> </main> </> ); }
incorrect:
import useFormState from "react-dom";

correct (nextjs 14):
import { useFormState } from "react-dom";
Answer
Asian swamp eelOP
ok
thx it work and now its run on development build !!!
close!!!