China has steadily accumulated U.S. Treasury securities over the decades. In December 2019, China owns about 5% ($1.07 trillion) of the U.S. national debt.
China has been in a trade surplus with the US since 1985.
China receives USD for goods sold to the US, but needs to pay workers in RMB. The USD is sold to get RMB, resulting in an increase in supply of USD, and demand for RMB.
The People’s Bank of China actively intervenes by buying available excess USD from exporters with RMB. The PBOC then prints the RMB as required. This keeps USD rates high, and hence China accumulates USD as forex reserves.
China keeps RMB artificially low to result in cheaper export prices, keeping its goods competitive.
This strategy generally leads to inflation, but China manages this via subsidies and price controls.
China has to continue to purchase US debt to ensure price competitiveness, or risk having a trade deficit, which is harmful to their export-oriented economy.