When someone post a piece of data, I want to use that data to drive show/hide of a section, but I don't want to display that piece of data.
Initially I declared a "data field" in the form, but I found "data field" does not show up in form xml, which means I cannot use it to prefill data.
Then I used a text field but made it hidden. The text field is in the form xml, so I can prefill it with data, but I am just wondering is this the right approach?
Using a data field is the correct way to do this, by default a data field is not included in the submission data which also impacts pre-fill of data values. Go to the data tab for the data field and select "Include in Submission Data" and configure appropriately for your pre-fill data.