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

然后就可以了

相关推荐
spmcor4 分钟前
React 架构师之路:Next.js 全栈革命(第八篇)
前端·react.js
假如让我当三天老蒯5 分钟前
React基础、进阶(学习用)
前端·react.js·面试
spmcor11 分钟前
为什么页面越用越卡?——React组件内存泄漏的排查与修复
react.js
jt君4242616 小时前
React Native JSI 深入剖析 — 第 7 部分中文技术整理:把 C++ 能力接到 iOS 和 Android
react native
天蓝色的鱼鱼16 小时前
React Router v8 来了:react-router-dom 没了,老项目该怎么迁移?
前端·react.js
jt君4242617 小时前
React Native JSI 深入剖析 — 第 6 部分中文技术整理:跨 JS 与 C++ 两个世界的内存所有权
react native
无名氏同学1 天前
React 16-19 新特性
react.js
写代码的皮筏艇1 天前
React中的forwardRef
前端·react.js·面试
不知疲倦的老鸟1 天前
Node.js 库在浏览器里跑不了的教训
react.js·next.js