UpdateView.jsx:71 Uncaught TypeError: Cannot read properties of undefined (reading 'title')

148 views Asked by At

during the editing of blog data when I use value={post.title}, it is running successfully but after I refresh the whole code got disrupted. don't know why

      <img className={classes.image} src={url} alt="banner" />
      <FormControl className={classes.form}>
        <AddCircle fontSize="large" color="action" />
        <InputBase
          placeholder="Title"
          value={post.title}
          className={classes.textField}
        />
        <Button variant="contained" color="primary">
          Update
        </Button>
      </FormControl>
      <TextareaAutosize
        rowsMin={5}
        placeholder="Tell your story"
        className={classes.textarea}
        value={post.description}
      />
    </Box>````
1

There are 1 answers

0
saddam On

After refreshing the page the post is getting undefined... To resolve this you have to use ternary operator for value..

value =  {post ? post.title : ""}