javascript - Unable to find module: react-accordion component -
i making accordion in react-native.i have taken following steps:
1) in react-native project have install react-accordion-component using following commond:
npm install --save react-accordion-component
2) import index.android.js
:
'use strict'; import react, { appregistry, component, stylesheet, proptypes, toastandroid, touchableopacity, viewpagerandroid, text, view } 'react-native'; import { tab, tablayout } 'react-native-android-tablayout'; import 'react-accordion-component'; class poc extends component { constructor(props) { super(props); this.state = { pageposition: 0, }; } render() { var accordion = require('react-accordion-component'); var elements = []; elements.push({ title: 'element 1', onclick: function() { alert('hello world!') }, content: 'lorem ipsum...' }); elements.push({ title: 'element 2', onclick: function() { }, content: 'lorem ipsum...' }); return ( <view> <tablayout style={styles.tablayout} selectedtab={this.state.pageposition} ontabselected={_setpageposition.bind(this)}> <tab name="s"/> <tab name="o"/> <tab name="a"/> <tab name="p"/> </tablayout> <viewpagerandroid style={styles.viewpager} ref={viewpager => { this.viewpager = viewpager; }} onpageselected={_setpageposition.bind(this)}> <view > react.render(<accordion elements={elements} />, document.getelementbyid('accordion-example')); </view> <view style={styles.content}> <text>tab 2 content</text> </view> <view style={styles.content}> <text>tab 3 content</text> </view> <view style={styles.content}> <text>tab 4 content</text> </view> </viewpagerandroid> </view> ); } } function _setpageposition(e:event) { const pageposition = e.nativeevent.position; this.setstate({ pageposition }); // bad viewpagerandroid doesn't support prop updates, // work around forwarding changes using exposed api this.viewpager.setpage(pageposition); } const styles = stylesheet.create({ tablayout: { flex: 1, backgroundcolor: '#ddd' }, viewpager: { height: 200, }, content: { padding: 10, } }); appregistry.registercomponent('poc', () => poc);
but when run on emulator, gives following error:
requiring unknown module "react-accordion-component".
please me resolve problem.
it looks have these 2 statements going on:
at top of file:
import react-accordion-component
and in render function:
var accordion = require('react-accordion-component')
delete import statement, , replace with
var accordion = require('react-accordion-component')
so, should now:
'use strict'; import react, { appregistry, component, stylesheet, proptypes, toastandroid, touchableopacity, viewpagerandroid, text, view } 'react-native'; import { tab, tablayout } 'react-native-android-tablayout'; var accordion = require('react-accordion-component'); class poc extends component { constructor(props) { super(props); this.state = { pageposition: 0, }; } render() { var elements = []; elements.push({ title: 'element 1', onclick: function() { alert('hello world!') }, content: 'lorem ipsum...' }); ...
Comments
Post a Comment