How to export method and variables in react?
How to use globally any method or variable in react?
Need to create a helper.js file or as you wish according to your
requirement. Then create method or variable but remember that use “export”
keyword before function or variable as below code:
Helper.js
export function days(day) {
if (day === '1') {
return 'Monday';
} else if (day === '2') {
return 'Tuesday';
} else if (day === '3') {
return 'Wednesday';
} else if (day === '4') {
return 'Thursday';
} else if (day === '5') {
return 'Friday';
} else if (day === '6') {
return 'Saturday';
} else if (day === '7') {
return 'Sunday';
} else {
return 'Good Day';
}
}
var theMonths = ["January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November", "December"];
export function dateFormates(date) {
var today = new Date(date);
var dd = today.getDate();
var mm = today.getMonth(); //January is 0!
var yyyy = today.getFullYear();
mm = theMonths[mm];
return mm + ' ' + dd + ' ' + yyyy;
}
import {myCompanyName} from '../assets/js/helpers'
{dateFormates(this.props.createDate)}
axios.put(baseUrl+'api/'+id, detailObject)
No comments:
Note: Only a member of this blog may post a comment.