Suppose we are given a vector field ##\vec F(x,y,z)=\langle f(x,y,z),g(x,y,z),h(x,y,z)\rangle## that has a potential function ##\phi## and we wish to recover the potential function. We know that we must have##\nabla \phi =\vec F##, so ##\phi_x = f,\, \phi_y=g,\, \phi_z = h##. This means we can recover ##\phi## by integrating the components of ##\vec F##.

To look at a particular example, consider $$
\vec F =\langle 2xz^3+e^z,-z\sin(yz),3x^2z^2-y\sin(yz)+xe^z\rangle$$Our unknown potential function ##\phi## must satisfy$$
\phi_x=2xz^3+e^z,\, \phi_y=-z\sin(yz),\,\phi_z=3x^2z^2-y\sin(yz)+xe^z$$Students often solve this type of problem by taking the anti-partial derivative of each equation:$$
\phi = \int 2xz^3+e^z\,\partial x = x^2z^3+xe^z$$ $$
\phi = \int -z\sin(yz)\, \partial y=\cos(yz)$$ $$
\phi = \int 3x^2z^2-y\sin(yz)+xe^z\, \partial z=x^2z^3+\cos(yz)+xe^z$$
where I have used the ##\partial## symbol in the integrals to emphasize that it is an anti-partial derivative in each case. I have also left off the "constants" of integration. Looking at these results, one may observe that the function ##\phi## can be discerned by "taking the new part of each result but not repeating". For example, you keep the ##\cos(yz)## from the second integral, but you don't keep the ##xe^z## and ##\cos(yz)## from the last integral because you already have them. So using this method, we get$$
\phi(x,y,z) = x^2z^3+\cos(yz)+xe^z$$and it is easy to check that ##\nabla \phi = \vec F##.

The problem with this method is at the last step where you build the formula for ##\phi## by inspection of the three antiderivatives above. Exactly what you are looking for in the inspection and the rules for building the potential function are not well defined and can lead to wrong answers. To demonstrate this, consider the 2-D example $$\vec F(x,y) = \langle P(x,y),Q(x,y)\rangle
= \langle 2\cos(2x)\cos^2(y),-\sin(2x)\sin(2y)\rangle$$ Here it is easy to see that ##Q_x=P_y## so there is no doubt there is a potential function ##\phi(x,y)##. So, using the above method:$$
\phi = \int 2\cos(2x)\cos^2(y)\, \partial x = \sin(2x)\cos^2(y)$$ $$
\phi = \int -\sin(2x)\sin(2y)\,\partial y =\frac{\sin(2x)\cos(2y)} 2$$Since these terms are different, we keep both of them, giving $$\phi(x,y) = \sin(2x)\cos^2(y)+\frac{\sin(2x)\cos(2y)} 2$$ Unfortunately, for this ##\phi##, if you calculate it, you get $$\phi_x = 2\cos(2x)\cos^2(y) +\cos(2x)\cos(2y) \ne P(x,y)$$ so this is not the correct potential function.

So the "integrate all three components and build the potential from them" method is unreliable, even though it frequently works. Fortunately, the proper way to work such problems is just as easy and always works. So, let's look at the first example above. Doing the first integral correctly and not ignoring the constants of integration gives us$$
\phi = \int 2xz^3+e^z\,\partial x = x^2z^3+xe^z + u(y,z)$$ where ##u## is an unknown function of the other variables, since we did an anti-partial derivative. Now we use this version of ##\phi## to check ##\phi_y = g##:$$
\phi_y = \frac \partial {\partial y}( x^2z^3+xe^z )+u_y(y,z)= 0 +u_y(y,z) =z\sin(yz)$$so we get$$
u(y,z) = \int z\sin(yz)\partial y = -\cos(yz) + v(z)$$where now the constant of integration depends only on ##z##. Putting this value for ##u## in our formula for ##\phi## gives$$
\phi = x^2z^3+xe^z -\cos(yz) + v(z)$$Now all that remains is to take the partial of this with respect to ##z## and set it equal to the third component ##h(x,y,z)##:$$
\phi_z=3x^2z^2+xe^z+y\sin(yz)+v'(z)=3x^2z^2-y\sin(yz)+xe^z$$This implies ##v'(z)=0## so ##v## is a constant, which can be ignored. So we get our final version:$$
\phi = x^2z^3+xe^z -\cos(yz)$$It is the same answer, but there is no guesswork building the potential function.

Now let's try this method on the 2D example that didn't work before. Our first integration gives$$
\phi = \int 2\cos(2x)\cos^2(y)\, \partial x = \sin(2x)\cos^2(y) + w(y)$$Differentiating this with respect to ##y## and setting the result equal to the second component gives$$
\phi_y=\sin(2x)(-2)\sin(y)\cos(y)+w'(y)=-\sin(2x)\sin(2y)$$This tells us that ##w'(y)=0## since ##2\sin(y)\cos(y)=\sin(2y)##. So ##w## is constant and can be ignored. This leaves us with the correct potential function$$
\phi = \sin(2x)\cos^2(y)$$unlike the first method.