The names are set well in advance. For example, the first four north Atlantic hurricanes in 2022 will be named Alex, Bonnie, Colin, and Danielle. In fact, the names of the north Atlantic hurricane in 2022 will be exactly the same as those in 2016, with one exception. Hurricane Matthew in 2016 was a catastrophic category 5 storm that claimed a number of lives and that resulted in large economic losses. The name Matthew has been retired because of this, so the 13th named north Atlantic storm in 2022 will be named Martin rather than Matthew. The US recycles the names it uses on a six year basis, but the names of significant storms are retired and replaced with some new name.
Names for tropical cyclones elsewhere in the world follow a similar convention. Names are set well in advance, with the lists of names being recycled after some number of years. As was the case with Matthew, the names of catastrophic storms that result in a number of deaths and/or large economic impacts are retired from those lists.