That question is really generic, so i'll try to answer in a generic way.
As you can expect, the answer is 'That depends on what the click does'
If the button click adds one to a counter, the undo can subtract one from the same counter. In this case, once undone, the undo option should be disabled.
If the button click deletes a file, then the undo must recreate the file and fill it with the original content.
In general, in order to be able to do an undo, you need to persist the current status, before doing the action by the click, in order to be able to restore it from the result, if an undo is required. When the undo is done, then you must 'destroy' the containter that holded the status, because you cannot use it to 'repeat' the undo.
You will be aware that if more tan one undo is required, then you'll need to persist the status several times, being able to know the exact order of creation.
Hope this helps