In the present study, a maleic acid-functionalized exfoliated graphite/calcium hydroxide (MA-EG/Ca(OH)2) was constructed and employed as a novel inorganic–organic nanocomposite for an efficient dispersive solid-phase microextraction (DSPME) of trace levels of sunset yellow (SY), a synthetic food dye in foodstuff samples before UV–Vis determination. To identify and characterize of the sorbent, various analytical techniques were utilized, including, Fourier transform-infrared spectroscopy (FT-IR), X-ray diffraction (XRD), field emission scanning electron microscopy (FESEM), energy dispersive X-ray spectroscopy (EDX), and Brunauer-Emmett-Teller (BET) analyses. The MA-EG/Ca(OH)2 exhibited a specific surface area of 40.35 m2 g−1 and adsorption capacity of 46.72 mg g−1 towards SY. Central composite design (CCD) in conjunction with a response surface methodology (RSM)-based ANOVA analysis was applied for evaluation and optimization of effective factors including pH (X1), sorbent mass (X2), contact time (X3), and elution volume (X4). According to the results, the optimum values were pH: 6.0, sorbent mass: 12 mg, contact time: 12 min, and elution volume: 0.18 µL. Under theses optimized conditions, DSPME/UV–Vis determination demonstrated a linear range of 50–4800 ng mL−1, a limit of detection (LOD) of 12.45 ng mL−1, and a limit of quantification (LOQ) of 41.49 ng mL−1 (n = 3). The relative standard deviation (RSD) at low concentration level (50–500 ng mL−1) of SY was 4.58 %. Recovery values in different concentration levels were in the range of 96.4–102.9 %. Overall, the proposed method showed the superior features, including ease of synthesizing the sorbent, acceptable LOD and LOQ values, remarkable sensitivity, a wide operational range, good reusability (up to five cycles), environmentally friendly as well as cost-effectiveness, that make it a promising candidate for the analysis of SY in foodstuff samples.