Gutenberg: Dynamic Block – Show saved data in the editor

You just need to get value from attributes, and set to <select>
In your case it will be like this: <select value={ props.attributes.category_id } onChange={ setCategory }>

Generally, you thinking in a right way, but variable that you declare at 13 row is not available outside of {}, and you set value to undefined.