I continue to encounter the same error while attempting to deliver data to this form

Encountering an error that says: TypeError: Cannot read properties of null (reading 'persist')

useEffect(() => {
    if (edit) {
      console.log(item)
      setValues(item!);
    } 
    document.body.style.overflow = showModal ? "hidden" : "";
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [edit, showModal]);
  const formik = useFormik({
    initialValues: {
      id: null as string | number | null,
      brandDescription: "",
      brandShortDescription: "",
      imagePath: null as string | number | null,
      statusDescription: false,
    },
    validationSchema: Yup.object({}),
    onSubmit: async (values, helpers) => {
      const filteredValue = {
        codigoMarca: values?.id,
        descripcionMarca: values?.brandDescription,
        estatus: values?.statusDescription ? 'A' : 'C',
        descripcionCortaMarca: values?.brandShortDescription,
      };
      await request(filteredValue)
      helpers.resetForm();
      handleModal();
    },
  });

  const setValues = (values: BrandsFront | undefined) => {
   const newValue = {
      id: values!.id,
      brandDescription: values!.brandDescription,
      brandShortDescription: values!.brandShortDescription,
      imagePath: '',
      statusDescription: values!.statusDescription === "Activo" ? true : false,
    };
    formik.setValues(newValue); 
  };
<Autocomplete
  id="asynchronous-brands"
  isOptionEqualToValue={(opt, value) => opt.id === value.id}
  value={formik.values.brandDescription}
  getOptionLabel={(option) => option.label}
  options={brands}
  onInputChange={formik.handleChange}
  onChange={formik.handleChange}
  inputValue={formik.values.brandDescription}
  renderInput={(params) => (
   <TextField
     sx={{-- styles --}}
     {...params}
     placeholder="Descripción de Marca"
    />
   )}
  size="small"
 />

Facing issues with the Autocomplete component from material UI, made several attempts to adjust props but still receiving the same error message

Answer №1

When you encounter an error message indicating that you cannot access a property of a null object, like the "persist" property in this case, it is usually because the property is called without checking if the object is null or not. Adding the optional chaining operator "?." can help resolve this issue. More information on how to use this operator can be found in this documentation.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring the capabilities of window opener in AngularJS applications

I am facing an issue with a function that utilizes an API to redirect me to a callback URL. After this redirection, I need to execute a function in my core JavaScript. If I keep the function separate from AngularJS and use window.opener, it works fine. How ...

Issue with combining overflow-x, Firefox, and JavaScript

In Firefox, an issue arises that does not occur in other browsers. To see the problem in action, please visit this example page: -removed- Try selecting a page other than the home page. The window will scroll to your selection. You can then scroll down u ...

jade, express, as well as findings from mysql

My goal is to display the results of an SQL query in Jade, which pulls data from a table of banners. Each banner has a unique id and falls under one of three types. Here is my current code : express : connection.query("SELECT * FROM banner_idx ORDER BY ...

Text displaying as actionable icons

In my React project, I am utilizing material-table (https://material-table.com/#/) and have successfully imported the necessary icons. However, when viewing the action bar, the icons are displaying as plain text instead of the Material Icon. import React, ...

Guide to generating a PDF file and utilizing a Node.js program for the download process

Seeking assistance in creating a button using my Node.js application to generate a downloadable PDF file filled with information from a PostgreSQL database. Any help is greatly appreciated! ...

What is the process for retrieving the chosen country code using material-ui-phone-number?

When incorporating user input for phone numbers, I have opted to utilize a package titled material-ui-phone-number. However, the challenge arises when attempting to retrieve the country code to verify if the user has included a 0 after the code. This infor ...

Invoking a JavaScript class using a script tag

In my code, I have a class declaration in a script that is imported before the body tag: $(document).ready(function(){ var FamilyTree = function() { }; FamilyTree.prototype.displayMessage=function() { alert("test"); } }); Then, within the bo ...

Looking for a method to substitute "test" with a different value

Showing a section of the menu using <li id="userInfo" role="presentation" data-toggle="tab" class="dropdown"> <a href="#" name="usernameMenu" class="dropdown-toggle" data-toggle="dropdown" role="button"> <span class="glyphicon glyph ...

Chokidar operates smoothly from the command line, but fails to function properly when invoked through the use of 'npm run'

I've implemented a script that monitors Tailwind CSS files using Chokidar. The script works perfectly when I execute the command in the CLI using chokidar 'tailwind.config.js' --initial=true -c 'npm run build-tailwind'. It successf ...

Ways to ensure that your Angular component.ts file is executed only after the body has completely loaded without relying on any external

I am attempting to add an event listener to an element created with a unique identifier using uuid, but I keep getting an error that states "Cannot read properties of null (reading 'addEventListener')" export class CommentItemComponent implements ...

There seems to be a problem with create-react-app as it is not being recognized as a valid cmdlet, function, script file, or program

I currently have Node(v6.10.3) and npm(3.10.10) installed on my computer system. After successfully installing create-react-app, I attempted to create a new project by running the command: create-react-app sample-app. However, an error message appeared: ...

Developing a Next.js application using Typescript can become problematic when attempting to build an asynchronous homepage that fetches query string values

Having recently started delving into the world of React, Next.js, and Typescript, I must apologize in advance if my terminology is not entirely accurate... My current learning project involves creating an app to track when songs are performed. Within the ...

How to properly display an Angular Template expression in an Angular HTML Component Template without any issues?

When writing documentation within an Angular App, is there a way to prevent code from executing and instead display it as regular text? {{ date | date :'short'}} Many sources suggest using a span element to achieve this: <span class="pun"&g ...

The Material Table in Angular is having issues with sorting functionality

I tried implementing the basic example from the angular material website, which displays a table with accurate data but the sorting functionality is not working as expected. For reference, you can view the StackBlitz demo here: https://stackblitz.com/edit ...

Guide to retrieving a string value rather than Json output with a mongodb aggregate function

I have a function that retrieves the value of the 'minHospitalization' field from the database. The response from this function is '[{"minHospitalization":1}]' Instead of returning the value in JSON format, I want to return just ' ...

Can metadata be attached to data models in Angular for annotation purposes?

Looking to add some metadata annotations to a simple data model export class Certification { title: string; certificationType?: CertificationType; validTo?: number; description?: string; externalIdentifier: Guid; constructor() { ...

Differences in disabled option value selection between jQuery legacy and updated versions

Recently, I upgraded the jQuery version in my project from 1.7.2 to 2.1.1 and included jquery migrate for fallback support. During testing, I encountered an issue with the value of a select element in jQuery versions 2.1.1 and 1.7.2: For version 1.7.2, t ...

The simple passport.js sign-up feature is not successful as it mistakenly believes that the username is already in

Currently, I am working on setting up a basic signup feature for my Node + Express + Sequelize application using passport.js. The database is empty at the moment, and I am utilizing the passport-local strategy to extract the user's email and password ...

When setting a value that has been explicitly casted, the original literal type remains intact for the new property or variable

After defining the constant MODE with specific values, I noticed something interesting: const MODE = { NONE: 0 as 0, COMPLETED: 1 as 1, DELETED: 2 as 2 } as const // In a CreateReactApp project, enums aren't available It became appar ...

What is the process for incorporating Dark Mode into a map?

Hey there! I'm diving into the world of web development and experimenting with a new react google maps package. I used npm i @vis.gl/react-google--maps to install it. I'm curious if there's a way to switch the embedded google map on my webs ...