Accessing state from outside component’s class
-
Hey everyone! Got a quick question right here. Hope this is the right place to ask. I’ve been trying to access a state from outside the component class, inside a
withSelect
call, but I haven’t been successful :disappointed: Any ideas how to achieve this? Is it possible?const { withSelect } = wp.data; class SearchControl extends Component { constructor() { super( ...arguments ); this.state = { searchTerm: null }; } render() { ... } } export default withSelect( ( select, state ) => { const { getEntityRecords } = select( 'core' ); const { searchTerm } = state; return { posts: getEntityRecords( 'postType', 'post', { search: searchTerm } ), }; } )( SearchControl );
- The topic ‘Accessing state from outside component’s class’ is closed to new replies.