Closed rockchalkwushock closed 7 years ago
Hi @rockchalkwushock
There is no performance bottleneck if you import the same libraries and modules. Babel optimizes it by default.
To use translate in all components, you can use the HOC or using Context
import { withTranslate } from 'react-redux-multilingual'
import React, { PropTypes } from 'react';
const HomePage = ({ translate }) => (
<div className='homepage'>
<h1>{translate('hello')}</h1>
</div>
);
HomePage.propTypes = {
translate: PropTypes.func
};
export default withTranslate(HomePage)
Context
const HomePage = (props, context) => {
return (
<div>
{context.translate('hello', { name: 'John Doe' })}
</div>
)
}
HomePage.contextTypes = {
translate: React.propTypes.func
}
module.exports = HomePage
I'm curious if it is possible to provide
translate()
to all the components throughreact-router
. So basically it would be provided to all children of the home route? I'm trying to find a way to limit how many times I am importing in the same libraries and modules for better performance. I'm going to keep playing around with it; but if you have any ideas I'd greatly appreciate it! Great package by the way really easy to use đindex.js
Root.jsx
dynamicRouting.js
AppContainer.jsx
App.jsx
HomePage.jsx