The French royal house (unlike the English) followed Salic Law: Only men could rule France and only men of the royal line. This was a simple, orderly decision rule (which had the additional virtue of excluding English claimants to the French throne,) but occasionally male French royal lines petered out. Then what?
Fortunately, in some generations, kings sired more than one son ("heir and a spares.") When this happened, the elder would become King, and the younger sons would become cadet "just-in-case" branches. If--when--the royal male line died out, as it did from time to time, the French would go back to the cadet branch to select the next male heir (after a war of succession.)
In this manner, France had three great dynasties: the Capetians (987 - 1328), the Valois (1328-1589) and the Bourbon (1589 - 1830). I've tried to give you an idea in the attached screenshot of what these lines look like. They were all descendants of Hugh Capet, but Louis IX--"Saint Louis" (1214-1270)-- had two sons. The elder became King Philip III, born in 1245, and his descendents were both the last of the Capetians and the Valois dynasty. Louis IX's younger son, Robert, born in 1256, founded a cadet dynasty and his descendent, Henri IV, would emerge in 1589 to found the Bourbon dynasty.
Philip III also had two sons. The elder, Philip IV (1285-1314)--nicknamed "the Fair" was a notable king, but nearly the last in the sputtering Capetian line. Three of his sons and one grandson became kings after him--Louis X, "the quarrelsome"; Louis X's short-lived son, John I, "the Posthumous"; Philip V, "the Tall", and Charles IV, "the Handsome"--and then there were no more males. The Capetian line was done. Philip III's younger son, Charles, Count of Valois, and his cadet branch then came into their own. Charles's son, Philip VI, aptly nicknamed "the Fortunate," fought a bitter succession battle with the English (one of the causes of the Hundred Years War) to become the first Valois king in 1328. He. When the Valois line died out 260 years later, the next in line was Henri IV, the eleventh generation of the cadet branch sired by Louis IX. Given the several hundred years that had passed (and his Protestantism), it is easy to see why many challenged his claim and why he needed to establish his authority.
The turbulence and decadence that marked the last of the Capetians, by the way, was one of the inspirations for "Game of Thrones."