|
We may end up passing all text as props, so we might consider instead: Originally posted by @razor-x in #1 (comment) |
Answered by
razor-x
May 25, 2023
Replies: 5 comments 4 replies
|
@mikewuu What do you think of exposing the text as props using this interface / pattern? |
1 reply
|
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',
} |
0 replies
|
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',
} |
1 reply
|
Another option would be to just support render props everywhere instead: <DeviceCard device={device} name={ (deviceName) => <p>dev: : {deviceName}</p> } /> |
1 reply
|
Closing this as the |
1 reply
Answer selected by
razor-x
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


Closing this as the
t.system we are using is working for now.