事实是,在某些情况下,这个问题又回到了我身上。在这种情况下,我想从另一个文件(用于代码清理)声明 LOCAL CONFIG OBJECT,但不知道该怎么做。请问我能解释一下吗?
我目前的情况是文件很长且不可读。我想从另一个文件中获取“本地配置对象”:
react-native-calendars 的本地配置对象如下所示:
import { LocaleConfig } from "react-native-calendars"; LocaleConfig.locales["fr"] = { monthNames: [ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre", ], monthNamesShort: ["Janv.", "Févr.", "Mars", "Avril", "Mai", "Juin", "Juil.", "Août", "Sept.", "Oct.", "Nov.", "Déc."], dayNames: ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"], dayNamesShort: ["shimon.", "Lun.", "Mar.", "Mer.", "Jeu.", "Ven.", "Sam."], today: "Aujourd'hui", }; LocaleConfig.defaultLocale = "fr";
我与组件的所有文件看起来像:
import React, { useEffect, useContext, useState } from "react"; import { StyleSheet, View } from "react-native"; import { Agenda } from "react-native-calendars"; import { CalendarItem } from "../customStyles/CalendarItem"; import { Context as BookingContext } from "../context/booking-context"; import { LocaleConfig } from "react-native-calendars"; LocaleConfig.locales["fr"] = { monthNames: [ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre", ], monthNamesShort: ["Janv.", "Févr.", "Mars", "Avril", "Mai", "Juin", "Juil.", "Août", "Sept.", "Oct.", "Nov.", "Déc."], dayNames: ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"], dayNamesShort: ["shimon.", "Lun.", "Mar.", "Mer.", "Jeu.", "Ven.", "Sam."], today: "Aujourd'hui", }; LocaleConfig.defaultLocale = "fr"; const UserHistory = () => { const { state, getAllMeetings } = useContext(BookingContext); const meetings = state.meetings; const loadMonthItems = month => { console.log("ffdffffffffffffffffffffffffffffffffffffffffffffff", month); }; useEffect(() => { getAllMeetings(); }, []); const renderItem = item => { return <CalendarItem item={item} />; }; return ( <View style={{ flex: 1 }}> <Agenda items={meetings} loadItemsForMonth={loadMonthItems} // selected={moment().format("YYYY-MM-DD")} selected={"2020-11-22"} renderItem={renderItem} theme={{ "stylesheet.agenda.list": { container: { flexDirection: "column", borderColor: "yellow", borderWidth: 1, }, dayNum: { fontSize: 16, fontWeight: "200", }, dayText: { fontSize: 14, fontFamily: "heebo", color: "green", backgroundColor: "rgba(0,0,0,0)", marginTop: 0, }, day: { width: 63, alignItems: "center", justifyContent: "flex-start", marginTop: 32, borderColor: "red", borderWidth: 1, }, today: { color: "blue", }, }, }} style={{ borderWidth: 3, borderColor: "gray", }} /> </View> ); }; const styles = StyleSheet.create({}); export default UserHistory;