-
We may end up passing all text as props, so we might consider instead: Originally posted by @razor-x in #1 (comment) |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 4 replies
-
@mikewuu What do you think of exposing the text as props using this interface / pattern? |
Beta Was this translation helpful? Give feedback.
-
It is intended to work like this. How would this work with children instead? export type DeviceCardProps = UseDeviceParams & { t?: DeviceCardText }
interface DeviceCardText {
device_id: string
device_name: string
}
export const DeviceCard = ({ t = defaultDeviceCardText, ...props }: DeviceCardProps): ReactElement => {
const { device } = useDevice(props)
return (
<div>
<p>{t.device_name}: {device.device_name}</p>
<p>{t.device_id}: {device.device_id}</p>
</div>
}
export const defaultDeviceCardText = {
device_name: 'Device Name',
device_id: 'ID',
} |
Beta Was this translation helpful? Give feedback.
-
Ahh I get it now. This is for the app static text. Can we rename the external prop to labels? Instead of: <DeviceCard device={device} t={{ name: 'dev:' }}/>` It would be: <DeviceCard device={device} labels={{ name: 'dev:' }} /> As for the implementation, maybe something like: export type DeviceCardProps = UseDeviceParams & { labels?: Partial<typeof defaultLabels> }
export const DeviceCard = ({ labels, ...props }: DeviceCardProps): ReactElement => {
const { device } = useDevice(props)
const t = {...defaultLabels, ...labels }
return (
<div>
<p>{t.name}: {device.device_name}</p>
</div>
}
export const defaultLabels = {
name: 'Device Name',
} |
Beta Was this translation helpful? Give feedback.
-
Another option would be to just support render props everywhere instead: <DeviceCard device={device} name={ (deviceName) => <p>dev: : {deviceName}</p> } />
|
Beta Was this translation helpful? Give feedback.
-
Closing this as the |
Beta Was this translation helpful? Give feedback.
Closing this as the
t.
system we are using is working for now.