I'm working on sharing code between a React and a React Native application (as much as possible).
For that I'm using styled-components. I'm trying something like this for the template strings
const BUTTON_STYLE = `
display: flex;
flex-direction: row;
align-items: center;
align-self: center;
border-radius: 6px;
padding: 20px 20px;
margin: 0 2px;
background-color: ${(props: ButtonProps) =>
CUSTOM_BUTTON_STYLES[props.styleType].backgroundColor};
border: solid 1px ${(props: ButtonProps) => CUSTOM_BUTTON_STYLES[props.styleType].borderColor};
`;
I'm using it like this in web
export const StyledWebButton = styled.button<ButtonProps>`${BUTTON_STYLE}`;
And like this in React Native
export const StyledNativeButton = styled.TouchableOpacity<ButtonProps>`${BUTTON_STYLE}`;
Problem comes when using ${(props: ButtonProps) =>
. It does not get props
properly. That makes the template string useless because styled components is not passing the component's props properly.
Any ideas?
Thanks!