When putting out a car fire in the engine bay it's not recommended to use water but instead a fire extinguisher because it's possible that the water can cause the fire to spread if it's a fuel or oil fire.
It's best to keep a fire extinguisher in your vehicle to be able to hopefully put the fire out but you should always call the fire department as well to have them on their way just in case.
I have however had to use water to put out an engine fire in a truck I was working on due to a gas leak on the carburetor before.
The water put the fire out and didn't cause it to spread but it is possible for it to spread in some cases so if water is your only option to put the car fire out then you can and should try it because it sometimes can put the fire out if it's not too bad.
But if the fire gets too bad then you need to call the fire department.