react native中使用tailwind并配置自动补全

javascript 复制代码
import { View, Text } from 'react-native';
import tw from 'twrnc';

const MyComponent = () => (
  <View style={tw`p-4 android:pt-2 bg-white dark:bg-black`}>
    <Text style={tw`text-md text-black dark:text-white`}>Hello World</Text>
  </View>
);

当然也支持条件变量

javascript 复制代码
// pass multiple args
tw.style('text-sm', 'bg-blue-100', 'flex-row mb-2');
// falsy stuff is ignored, so you can do conditionals like this
tw.style(isOpen && 'bg-blue-100');

重要的来了!配置vscode的补全

参考自React Native - Tailwind CSS autocomplete in VSCode for twrnc package

补全插件还是用的Tailwind CSS IntelliSense,需要添加vscode的配置并手动新建两个空文件

在下图添加

新建一个空文件tailwind.config.js

然后就可以了

相关推荐
是你的小橘呀9 小时前
React Native 3:useEffect 自动请求接口 + 搜索功能 + 封装 Loading 组件
react native
是你的小橘呀11 小时前
React Native 2:列表渲染 + 后端接口搭建 + Fetch 请求数据
react native
JudithHuang11 小时前
React 列表与表单
react.js
JudithHuang11 小时前
React Context 跨层传值
react.js
JudithHuang11 小时前
React useRef 与 DOM
react.js
JudithHuang11 小时前
React useReducer 复杂状态
react.js
JudithHuang11 小时前
React 组件与 Props
react.js