Research suggests that myopia is possibly caused by a combination of two factors: genetics and environmental factors.
There would be many cases of heredity with regard to myopia. On the other hand, heredity alone is not able to explain the expansion of myopia in the population.
Then come the environmental factors. For example, long hours spent in front of screens would increase the risk of developing nearsightedness. Spending less time outdoors, having less sunlight exposure reduces the amount of dopamine secreted, a hormone that prevents the overgrowth of the eye.