Gutenberg: set category with dispatch

Set the category with id termId and post ID currentPostId:

wp.data.dispatch( 'core' ).editEntityRecord( 'postType', 'category', currentPostId, { 'pr-category': [ termId ] } );

Both termID and currentPostId need to be integers. use parseInt to enforce this if necessary.

Custom taxonomy

Same thing, just use your custom taxonomy slug instead of ‘category’:

wp.data.dispatch( 'core' ).editEntityRecord( 'postType', 'my-custom-taxonomy', currentPostId, { 'pr-category': [ termId ] } );

Set multiple categories

If you want to set categories with term ID’s 24, 45 and 87:

wp.data.dispatch( 'core' ).editEntityRecord( 'postType', 'category', currentPostId, { 'pr-category': [ 24, 45, 87 ] } );