Skip to content

Create.js - "Insert" doesn't return 'data' #10

@ReinerKnudsen

Description

@ReinerKnudsen

In the Create.js file we find the following code:

    const { data, error } = await supabase
      .from('recipes')
      .insert([{ title, method, rating }])

    if (error) {
      console.log(error)
      setFormError('Please fill in all the fields correctly.')
    }
    if (data) {
      console.log(data)
      setFormError(null)
      navigate('/')
    }
  }

Yet insert doesn't provide a data object (anymore?). Therefore datais always undefined and the positive if-branch won't run.

Solution:

In the if-branch simply replace the oc
de like this:

    if (error) {
      console.log(error)
      setFormError('Please fill in all the fields correctly.')
    } else {
      setFormError(null)
      navigate('/')
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions