I'm trying to configure my new react-redux application to use the new features of React-Redux. The official documentation says
React Redux now offers a set of hook APIs as an alternative to the existing connect() Higher Order Component.
I have been trying to find some helping articles related to Hooks API with some real examples but all react-redux Apps are using connect function. Official documentation also shows very basic examples.
I want to change the connect functions in my App with useSelector (offered by Hooks API).
Here is an example code snippet from my application.
//MessagesListContainer
export default connect(
// mapStateToProps
(state:State) => ({
activeUser: getActiveUser(state),
messages: getMessagesList(state),
})
)(MessagesList)
//Selectors
export const getActiveUser = (state: State) => state.activeUser;
export const getMessagesList = (state : State) => (
Object.keys(state.messages).map((key : any)=> state.messages[key])
)
export interface IMessagesListProps {
activeUser?: User;
messages?: Message[];
}
/**
* Messages List
*/
export default class MessagesList extends PureComponent<IMessagesListProps> {
.
.
.
}