我的公司正在使用recompose作为我们的状态管理工具。我们正在重构我们的应用程序以使用钩子。对于以下代码,如何用react hook组件替换重组组件?
我知道withState变成useState,例如:
withState('something', 'setSomething', null)
Run Code Online (Sandbox Code Playgroud)
变成
const [something, setSomething] = useState(null);
Run Code Online (Sandbox Code Playgroud)
会是什么withProps,withHandlers,compose,hoistStatics和lifecycle改变?
怎么会mapStateToProps和mapDispatchToProps工作?
import { compose, hoistStatics, withHandlers, withState, withProps, lifecycle } from 'recompose';
import { connect } from 'react-redux'
import myComponent from './myComponent'
const mapStateToProps = (state, props) => {
return {
}
};
const mapDispatchToProps = (dispatch) => {
return bindActionCreators({
}, dispatch)
};
const enhancer = compose(
connect(mapStateToProps,mapDispatchToProps),
withProps(props => ({
myProp: …Run Code Online (Sandbox Code Playgroud) 如何将自定义注销按钮添加到我的抽屉?我尝试了几件事,但似乎找不到解决方案。这就是我被困的地方。
import React from 'react';
import {TouchableOpacity, Image, Text} from 'react-native';
import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import {createDrawerNavigator} from '@react-navigation/drawer';
const HomeStack = createStackNavigator();
const Drawer = createDrawerNavigator();
// Screens
import HomeScreen from '../containers/HomeContainer';
const HomeStackScreen = () => {
return (
<HomeStack.Navigator>
<HomeStack.Screen
name="My Thoughts"
component={HomeScreen}
/>
</HomeStack.Navigator>
);
};
function DrawerNavigation() {
return (
<Drawer.Navigator>
<Drawer.Screen name="Home" component={HomeStackSceen} />
<TouchableOpacity>
<Text>Logout</Text>
</TouchableOpacity>
</Drawer.Navigator>
);
}
export const AppNavigation = () => {
return (
<NavigationContainer> …Run Code Online (Sandbox Code Playgroud) reactjs react-native react-navigation react-navigation-drawer