我将我的 React Native 应用程序从 0.48.3 升级到 0.59.8 一切正常,直到启动模拟器。然后出现这个错误:
error: bundling failed: Error: Unable to resolve module
`@babel/runtime/helpers/interopRequireDefault` from
`E:\als\variant\generic\index.android.js`: Module
`@babel/runtime/helpers/interopRequireDefault` does not exist in the
Haste module map
Run Code Online (Sandbox Code Playgroud)
这是我的 Package.json :
"dependencies": {
"@babel/polyfill": "^7.4.4",
"@babel/runtime": "^7.0.0-beta.55",
"babel-loader": "^8.0.5",
"content-disposition": "^0.5.2",
"core-js": "^3.0.1",
"react": "16.8.6",
"react-dom": "16.8.6",
"react-loader": "^2.4.5",
"react-native": "0.59.8",
"react-redux": "^5.0.6",
"react-router-dom": "^5.0.0",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0",
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@babel/plugin-proposal-decorators": "^7.4.4",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.4.4",
"@babel/plugin-transform-block-scoping": "^7.0.0",
"@babel/plugin-transform-flow-strip-types": "^7.4.4",
"@babel/plugin-transform-react-jsx-source": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.4.4",
"@babel/preset-env": "^7.4.3",
"@babel/preset-flow": …Run Code Online (Sandbox Code Playgroud) 我有两个组成部分:
我想将Titles的值(处于子状态)传递给父Component。这是我的子组件代码:
export default function ChildApp(props) {
const [titles,setTitles] = React.useState("")
return (
<Button title="submit" onPress={()=>setTitles("asma")}/>
);
}
Run Code Online (Sandbox Code Playgroud)
这是我的父组件:
this.state = { titles:"foo"}
setTitles = titles => this.setState({ titles })
// i need the value of Titles to be set in state
export default class ParentApp extends Component {
const titles = this.state.titles
<ChildApp titles={titles} setTitles={this.setTitles} />
}
Run Code Online (Sandbox Code Playgroud)
看起来很容易做到,但这是我第一次使用功能组件。你能帮我吗 ?