1
0
mirror of https://github.com/alice-lg/alice-lg.git synced 2024-05-11 05:55:03 +00:00

40 lines
707 B
React
Raw Normal View History

2018-06-26 17:09:34 +02:00
import React from 'react'
import {connect} from 'react-redux'
/*
* Content Component
*/
2018-06-26 17:09:34 +02:00
function ContentComponent(props) {
let key = props.id;
let defaultValue = props.children;
if (!key) {
return <span>{defaultValue}</span>;
}
// Traverse content by key, if content is found
// return content, otherwise fall back to the default
let tokens = key.split(".");
let resolved = props.content;
for (let part of tokens) {
resolved = resolved[part];
if (!resolved) {
break;
}
}
if (!resolved) {
resolved = defaultValue;
}
return (<span>{resolved}</span>);
}
export default connect(
(state) => ({
content: state.content
})
2018-06-26 17:09:34 +02:00
)(ContentComponent);