  The production of inclusive, prompt and non-prompt J/$\psi$ was studied for
the first time at midrapidity ($ -1.37 < y_{\rm cms} < 0.43$) in p$-$Pb
collisions at $\sqrt{s_{\rm NN}} = 8.16$ TeV with the ALICE detector at the
LHC. The inclusive J/$\psi$ mesons were reconstructed in the dielectron decay
channel in the transverse momentum ($p_{\rm T}$) interval $0 < p_{\rm T} < 14$
GeV/$c$ and the prompt and non-prompt contributions were separated on a
statistical basis for $p_{\rm T} > 2$ GeV/$c$. The study of the J/$\psi$ mesons
in the dielectron channel used for the first time in ALICE online
single-electron triggers from the Transition Radiation Detector, providing a
data sample corresponding to an integrated luminosity of $689 \pm 13 \mu{\rm
b}^{-1}$. The proton$-$proton reference cross section for inclusive J/$\psi$
was obtained based on interpolations of measured data at different
centre-of-mass energies and a universal function describing the $p_{\rm
T}$-differential J/$\psi$ production cross sections. The $p_{\rm
T}$-differential nuclear modification factors $R_{\rm pPb}$ of inclusive,
prompt, and non-prompt J/$\psi$ are consistent with unity and described by
theoretical models implementing only nuclear shadowing.
