I'm doing this react-native project and i am using this method to organize my project files but i don't know how to declare functions inside a const.
import React from 'react';
import { View, ListView, Text } from 'react-native';
const Category = (props) => {
const ds = ListView.DataSource({rowHasChanged : (r1, r2) => r1 !== r2});
// how to declare function here?
return (
<View>
<ListView
dataSource={ds}
renderRow={(rowData) => <Text>{rowData}</Text>}
renderSeparator={// how to put function reference here?}
/>
</View>
);
}
What you called 'a const' is in fact an arrow function. In JS, you can add any nested functions as you want:
const Category = (props) => {
const ds = ListView.DataSource({rowHasChanged : (r1, r2) => r1 !== r2});
// how to declare function here?
// You can declare another arrow function if you want:
const foo = () => console.log('arrow');
// Or a standard function
function bar() { console.log('standard'); }
// Even a function returning a function :-)
function baz() { return function() {...} }
const renderCustomComponent = () => <div>____</div>
return (
<View>
<ListView
dataSource={ds}
renderRow={(rowData) => <Text>{rowData}</Text>}
renderSeparator={ renderCustomComponent } {/* Here goes your reference */}
/>
</View>
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With