Check out example codes for "how to add category to recent posts widget wordpress". It will help you in understanding the concepts better.

Code Example 1

add_filter( 'widget_posts_args', 'my_widget_posts_args');
function my_widget_posts_args($args) {
	if ( is_category() ) { //adds the category parameter in the query if we display a category
		$cat = get_queried_object();
		return array(
			'posts_per_page' => 10,//set the number you want here 
			'no_found_rows' => true, 
			'post_status' => 'publish', 
			'ignore_sticky_posts' => true,
			'cat' => $cat -> term_id//the current category id
	else {//keeps the normal behaviour if we are not in category context
		return $args;

Learn ReactJs, React Native from